<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Class: Origami::PDF</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Class</strong></td>
          <td class="class-name-in-header">Origami::PDF</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../files/origami/file_rb.html">
                origami/file.rb
                </a>
        <br />
                <a href="../../files/origami/acroform_rb.html">
                origami/acroform.rb
                </a>
        <br />
                <a href="../../files/origami/parser_rb.html">
                origami/parser.rb
                </a>
        <br />
                <a href="../../files/origami/encryption_rb.html">
                origami/encryption.rb
                </a>
        <br />
                <a href="../../files/origami/xfa_rb.html">
                origami/xfa.rb
                </a>
        <br />
                <a href="../../files/origami/metadata_rb.html">
                origami/metadata.rb
                </a>
        <br />
                <a href="../../files/origami/pdf_rb.html">
                origami/pdf.rb
                </a>
        <br />
                <a href="../../files/origami/catalog_rb.html">
                origami/catalog.rb
                </a>
        <br />
                <a href="../../files/origami/page_rb.html">
                origami/page.rb
                </a>
        <br />
                <a href="../../files/origami/header_rb.html">
                origami/header.rb
                </a>
        <br />
                <a href="../../files/origami/trailer_rb.html">
                origami/trailer.rb
                </a>
        <br />
                <a href="../../files/origami/export_rb.html">
                origami/export.rb
                </a>
        <br />
                <a href="../../files/origami/xreftable_rb.html">
                origami/xreftable.rb
                </a>
        <br />
                <a href="../../files/origami/linearization_rb.html">
                origami/linearization.rb
                </a>
        <br />
                <a href="../../files/origami/signature_rb.html">
                origami/signature.rb
                </a>
        <br />
            </td>
        </tr>

        <tr class="top-aligned-row">
            <td><strong>Parent:</strong></td>
            <td>
                <a href="Object.html">
                Object
               </a>
            </td>
        </tr>
        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Main class representing a <a href="PDF.html">PDF</a> file and its inner
contents. A <a href="PDF.html">PDF</a> file contains a set of <a
href="PDF/Revision.html">Revision</a>.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000502">&lt;&lt;</a>&nbsp;&nbsp;
      <a href="#M000514">Catalog</a>&nbsp;&nbsp;
      <a href="#M000515">Catalog=</a>&nbsp;&nbsp;
      <a href="#M000478">add_fields</a>&nbsp;&nbsp;
      <a href="#M000509">add_new_revision</a>&nbsp;&nbsp;
      <a href="#M000504">add_to_revision</a>&nbsp;&nbsp;
      <a href="#M000505">alloc_new_object_number</a>&nbsp;&nbsp;
      <a href="#M000520">append_page</a>&nbsp;&nbsp;
      <a href="#M000500">append_subobj</a>&nbsp;&nbsp;
      <a href="#M000475">attach_file</a>&nbsp;&nbsp;
      <a href="#M000506">compile</a>&nbsp;&nbsp;
      <a href="#M000477">create_acroform</a>&nbsp;&nbsp;
      <a href="#M000482">create_xfa_form</a>&nbsp;&nbsp;
      <a href="#M000480">decrypt</a>&nbsp;&nbsp;
      <a href="#M000511">delete_object</a>&nbsp;&nbsp;
      <a href="#M000526">delete_xrefstm</a>&nbsp;&nbsp;
      <a href="#M000528">delinearize!</a>&nbsp;&nbsp;
      <a href="#M000488">deserialize</a>&nbsp;&nbsp;
      <a href="#M000531">enable_usage_rights</a>&nbsp;&nbsp;
      <a href="#M000481">encrypt</a>&nbsp;&nbsp;
      <a href="#M000523">export_to_graph</a>&nbsp;&nbsp;
      <a href="#M000524">export_to_graphml</a>&nbsp;&nbsp;
      <a href="#M000491">filesize</a>&nbsp;&nbsp;
      <a href="#M000498">find</a>&nbsp;&nbsp;
      <a href="#M000485">get_document_info</a>&nbsp;&nbsp;
      <a href="#M000486">get_metadata</a>&nbsp;&nbsp;
      <a href="#M000495">grep</a>&nbsp;&nbsp;
      <a href="#M000483">has_document_info?</a>&nbsp;&nbsp;
      <a href="#M000476">has_form?</a>&nbsp;&nbsp;
      <a href="#M000484">has_metadata?</a>&nbsp;&nbsp;
      <a href="#M000532">has_usage_rights?</a>&nbsp;&nbsp;
      <a href="#M000501">indirect_objects</a>&nbsp;&nbsp;
      <a href="#M000503">insert</a>&nbsp;&nbsp;
      <a href="#M000521">insert_page</a>&nbsp;&nbsp;
      <a href="#M000479">is_encrypted?</a>&nbsp;&nbsp;
      <a href="#M000527">is_linearized?</a>&nbsp;&nbsp;
      <a href="#M000530">is_signed?</a>&nbsp;&nbsp;
      <a href="#M000496">ls</a>&nbsp;&nbsp;
      <a href="#M000497">ls_no_follow</a>&nbsp;&nbsp;
      <a href="#M000489">new</a>&nbsp;&nbsp;
      <a href="#M000499">objects</a>&nbsp;&nbsp;
      <a href="#M000517">onDocumentClose</a>&nbsp;&nbsp;
      <a href="#M000516">onDocumentOpen</a>&nbsp;&nbsp;
      <a href="#M000518">onDocumentPrint</a>&nbsp;&nbsp;
      <a href="#M000522">pages</a>&nbsp;&nbsp;
      <a href="#M000512">physicalize</a>&nbsp;&nbsp;
      <a href="#M000487">read</a>&nbsp;&nbsp;
      <a href="#M000508">rebuildxrefs</a>&nbsp;&nbsp;
      <a href="#M000519">register</a>&nbsp;&nbsp;
      <a href="#M000510">remove_revision</a>&nbsp;&nbsp;
      <a href="#M000525">remove_xrefs</a>&nbsp;&nbsp;
      <a href="#M000492">save</a>&nbsp;&nbsp;
      <a href="#M000494">save_upto</a>&nbsp;&nbsp;
      <a href="#M000493">saveas</a>&nbsp;&nbsp;
      <a href="#M000490">serialize</a>&nbsp;&nbsp;
      <a href="#M000513">set_extension_level</a>&nbsp;&nbsp;
      <a href="#M000529">sign</a>&nbsp;&nbsp;
      <a href="#M000507">to_bin</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">

    <div id="class-list">
      <h3 class="section-bar">Classes and Modules</h3>

      Class <a href="PDF/Header.html" class="link">Origami::PDF::Header</a><br />
Class <a href="PDF/Instruction.html" class="link">Origami::PDF::Instruction</a><br />
Class <a href="PDF/LinearParser.html" class="link">Origami::PDF::LinearParser</a><br />
Class <a href="PDF/Revision.html" class="link">Origami::PDF::Revision</a><br />

    </div>

    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">V</td>
          <td>=</td>
          <td class="context-item-value">version</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">R</td>
          <td>=</td>
          <td class="context-item-value">revision</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Length</td>
          <td>=</td>
          <td class="context-item-value">params[:KeyLength]</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">P</td>
          <td>=</td>
          <td class="context-item-value">-1</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">EncryptMetadata</td>
          <td>=</td>
          <td class="context-item-value">params[:EncryptMetadata]</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">CF</td>
          <td>=</td>
          <td class="context-item-value">Dictionary.new</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">AuthEvent</td>
          <td>=</td>
          <td class="context-item-value">:DocOpen</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">CFM</td>
          <td>=</td>
          <td class="context-item-value">:AESV2</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Length</td>
          <td>=</td>
          <td class="context-item-value">params[:KeyLength] &gt;&gt; 3</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">StmF</td>
          <td>=</td>
          <td class="context-item-value">handler.StrF = :StdCF</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">XFA</td>
          <td>=</td>
          <td class="context-item-value">Stream.new(xdp, :Filter =&gt; :FlateDecode)</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">W</td>
          <td>=</td>
          <td class="context-item-value">[ 1, (xrefstm_offset.to_s(2).size + 7) &gt;&gt; 3, 2 ]</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Prev</td>
          <td>=</td>
          <td class="context-item-value">prev_xref_offset</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Size</td>
          <td>=</td>
          <td class="context-item-value">objset.size + 1</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Prev</td>
          <td>=</td>
          <td class="context-item-value">prev_xref_offset</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">XRefStm</td>
          <td>=</td>
          <td class="context-item-value">xrefstm_offset if options[:use_xrefstm] == true</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Size</td>
          <td>=</td>
          <td class="context-item-value">size + 1</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Root</td>
          <td>=</td>
          <td class="context-item-value">root</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Pages</td>
          <td>=</td>
          <td class="context-item-value">PageTreeNode.new.set_indirect(true)</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Root</td>
          <td>=</td>
          <td class="context-item-value">catalog.reference</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Size</td>
          <td>=</td>
          <td class="context-item-value">size + 1</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">BaseVersion</td>
          <td>=</td>
          <td class="context-item-value">Name.new(version)</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">ExtensionLevel</td>
          <td>=</td>
          <td class="context-item-value">level</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Root</td>
          <td>=</td>
          <td class="context-item-value">self &lt;&lt; cat</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">OpenAction</td>
          <td>=</td>
          <td class="context-item-value">action</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">WC</td>
          <td>=</td>
          <td class="context-item-value">action</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">WP</td>
          <td>=</td>
          <td class="context-item-value">action</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Names</td>
          <td>=</td>
          <td class="context-item-value">Names.new</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Count</td>
          <td>=</td>
          <td class="context-item-value">treeroot.Kids.length</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Parent</td>
          <td>=</td>
          <td class="context-item-value">treeroot</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">ID</td>
          <td>=</td>
          <td class="context-item-value">[ id, id ]</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Rect</td>
          <td>=</td>
          <td class="context-item-value">Rectangle[:llx =&gt; 0.0, :lly =&gt; 0.0, :urx =&gt; 0.0, :ury =&gt; 0.0]</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">V</td>
          <td>=</td>
          <td class="context-item-value">digsig ;</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">SigFlags</td>
          <td>=</td>
          <td class="context-item-value">InteractiveForm::SigFlags::SIGNATURESEXIST | InteractiveForm::SigFlags::APPENDONLY</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Location</td>
          <td>=</td>
          <td class="context-item-value">HexaString.new(location) if location</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">ContactInfo</td>
          <td>=</td>
          <td class="context-item-value">HexaString.new(contact) if contact</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Reason</td>
          <td>=</td>
          <td class="context-item-value">HexaString.new(reason) if reason</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Data</td>
          <td>=</td>
          <td class="context-item-value">self.Catalog</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">TransformParams</td>
          <td>=</td>
          <td class="context-item-value">UsageRights::TransformParams.new</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">V</td>
          <td>=</td>
          <td class="context-item-value">UsageRights::TransformParams::VERSION</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">Reference</td>
          <td>=</td>
          <td class="context-item-value">[ sigref ]</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">UR3</td>
          <td>=</td>
          <td class="context-item-value">digsig</td>
        </tr>
        </table>
      </div>
    </div>

    <div id="aliases-list">
      <h3 class="section-bar">External Aliases</h3>

      <div class="name-list">
                        <table summary="aliases">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">get_object</td>
          <td>-&gt;</td>
          <td class="context-item-value">[]</td>
        </tr>
                        </table>
      </div>
    </div>


    <div id="attribute-list">
      <h3 class="section-bar">Attributes</h3>

      <div class="name-list">
        <table>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">filename</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">header</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">revisions</td>
          <td class="context-item-value">&nbsp;[RW]&nbsp;</td>
          <td class="context-item-desc"></td>
        </tr>
        </table>
      </div>
    </div>
      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000488" class="method-detail">
        <a name="M000488"></a>

        <div class="method-heading">
          <a href="#M000488" class="method-signature">
          <span class="method-name">deserialize</span><span class="method-args">(filename)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Deserializes a <a href="PDF.html">PDF</a> dump.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000488-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000488-source">
<pre>
     <span class="ruby-comment cmt"># File origami/pdf.rb, line 170</span>
170:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">deserialize</span>(<span class="ruby-identifier">filename</span>)
171:         
172:         <span class="ruby-constant">Zlib</span><span class="ruby-operator">::</span><span class="ruby-constant">GzipReader</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">filename</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">gz</span><span class="ruby-operator">|</span>
173:           <span class="ruby-identifier">pdf</span> = <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">load</span>(<span class="ruby-identifier">gz</span>.<span class="ruby-identifier">read</span>)
174:         }
175:         
176:         <span class="ruby-identifier">pdf</span>
177:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000489" class="method-detail">
        <a name="M000489"></a>

        <div class="method-heading">
          <a href="#M000489" class="method-signature">
          <span class="method-name">new</span><span class="method-args">(init_structure = true)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Creates a <a href="PDF.html#M000489">new</a> <a href="PDF.html">PDF</a>
instance.
</p>
<table>
<tr><td valign="top"><em>init_structure</em>:</td><td>If this flag is set, then some structures will be automatically generated
while manipulating this <a href="PDF.html">PDF</a>. Set it if you are
creating a <a href="PDF.html#M000489">new</a> <a href="PDF.html">PDF</a>
file, this <em>must</em> <em>not</em> be used when parsing an existing
file.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000489-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000489-source">
<pre>
     <span class="ruby-comment cmt"># File origami/pdf.rb, line 185</span>
185:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">init_structure</span> = <span class="ruby-keyword kw">true</span>)
186: 
187:       <span class="ruby-ivar">@header</span> = <span class="ruby-constant">PDF</span><span class="ruby-operator">::</span><span class="ruby-constant">Header</span>.<span class="ruby-identifier">new</span>
188:       <span class="ruby-ivar">@revisions</span> = []
189:       
190:       <span class="ruby-identifier">add_new_revision</span>
191:       <span class="ruby-ivar">@revisions</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">trailer</span> = <span class="ruby-constant">Trailer</span>.<span class="ruby-identifier">new</span>
192: 
193:       <span class="ruby-identifier">init</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">init_structure</span>
194:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000487" class="method-detail">
        <a name="M000487"></a>

        <div class="method-heading">
          <a href="#M000487" class="method-signature">
          <span class="method-name">read</span><span class="method-args">(filename, options = {:verbosity =&gt; Parser::VERBOSE_INSANE})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Read and parse a <a href="PDF.html">PDF</a> file from disk.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000487-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000487-source">
<pre>
     <span class="ruby-comment cmt"># File origami/pdf.rb, line 163</span>
163:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">read</span>(<span class="ruby-identifier">filename</span>, <span class="ruby-identifier">options</span> = {<span class="ruby-identifier">:verbosity</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Parser</span><span class="ruby-operator">::</span><span class="ruby-constant">VERBOSE_INSANE</span>})
164:         <span class="ruby-constant">PDF</span><span class="ruby-operator">::</span><span class="ruby-constant">LinearParser</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">options</span>).<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">filename</span>)
165:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000502" class="method-detail">
        <a name="M000502"></a>

        <div class="method-heading">
          <a href="#M000502" class="method-signature">
          <span class="method-name">&lt;&lt;</span><span class="method-args">(object)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Adds a <a href="PDF.html#M000489">new</a> object to the <a
href="PDF.html">PDF</a> file. If this object has no version number, then a
<a href="PDF.html#M000489">new</a> one will be automatically computed and
assignated to him. It returns a Reference to this <a
href="Object.html">Object</a>.
</p>
<table>
<tr><td valign="top"><em>object</em>:</td><td>The object to add.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000502-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000502-source">
<pre>
     <span class="ruby-comment cmt"># File origami/pdf.rb, line 432</span>
432:     <span class="ruby-keyword kw">def</span> <span class="ruby-operator">&lt;&lt;</span>(<span class="ruby-identifier">object</span>)
433:       <span class="ruby-identifier">add_to_revision</span>(<span class="ruby-identifier">object</span>, <span class="ruby-ivar">@revisions</span>.<span class="ruby-identifier">last</span>)
434:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000514" class="method-detail">
        <a name="M000514"></a>

        <div class="method-heading">
          <a href="#M000514" class="method-signature">
          <span class="method-name">Catalog</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the current <a href="PDF.html#M000514">Catalog</a> <a
href="Dictionary.html">Dictionary</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000514-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000514-source">
<pre>
    <span class="ruby-comment cmt"># File origami/catalog.rb, line 46</span>
46:     <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Catalog</span>
47:       <span class="ruby-identifier">get_doc_attr</span>(<span class="ruby-identifier">:Root</span>)
48:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000515" class="method-detail">
        <a name="M000515"></a>

        <div class="method-heading">
          <a href="#M000515" class="method-signature">
          <span class="method-name">Catalog=</span><span class="method-args">(cat)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sets the current <a href="PDF.html#M000514">Catalog</a> <a
href="Dictionary.html">Dictionary</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000515-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000515-source">
<pre>
    <span class="ruby-comment cmt"># File origami/catalog.rb, line 53</span>
53:     <span class="ruby-keyword kw">def</span> <span class="ruby-constant">Catalog=</span>(<span class="ruby-identifier">cat</span>)
54:       <span class="ruby-comment cmt">#unless cat.is_a?(Catalog)</span>
55:       <span class="ruby-comment cmt">#  raise TypeError, &quot;Expected type Catalog, received #{cat.class}&quot;</span>
56:       <span class="ruby-comment cmt">#end</span>
57:       <span class="ruby-identifier">cat</span> = <span class="ruby-constant">Catalog</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">cat</span>) <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">cat</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Catalog</span>
58:       
59:       <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@revisions</span>.<span class="ruby-identifier">last</span>.<span class="ruby-identifier">trailer</span>.<span class="ruby-constant">Root</span>
60:         <span class="ruby-identifier">delete_object</span>(<span class="ruby-ivar">@revisions</span>.<span class="ruby-identifier">last</span>.<span class="ruby-identifier">trailer</span>[<span class="ruby-identifier">:Root</span>])
61:       <span class="ruby-keyword kw">end</span>
62:       
63:       <span class="ruby-ivar">@revisions</span>.<span class="ruby-identifier">last</span>.<span class="ruby-identifier">trailer</span>.<span class="ruby-constant">Root</span> = <span class="ruby-keyword kw">self</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">cat</span>
64:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000478" class="method-detail">
        <a name="M000478"></a>

        <div class="method-heading">
          <a href="#M000478" class="method-signature">
          <span class="method-name">add_fields</span><span class="method-args">(*fields)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Add a field to the Acrobat form.
</p>
<table>
<tr><td valign="top"><em>field</em>:</td><td>The <a href="Field.html">Field</a> to add.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000478-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000478-source">
<pre>
    <span class="ruby-comment cmt"># File origami/acroform.rb, line 51</span>
51:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add_fields</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">fields</span>)
52:       <span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-value str">&quot;Expected Field arguments&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">fields</span>.<span class="ruby-identifier">all?</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span> <span class="ruby-identifier">f</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Field</span>) }
53:       
54:       <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-constant">AcroForm</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">InteractiveForm</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">set_indirect</span>(<span class="ruby-keyword kw">true</span>)
55:       <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-constant">AcroForm</span>.<span class="ruby-constant">Fields</span> <span class="ruby-operator">||=</span> []
56:       
57:       <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-constant">AcroForm</span>.<span class="ruby-constant">Fields</span>.<span class="ruby-identifier">concat</span>(<span class="ruby-identifier">fields</span>)
58:       <span class="ruby-identifier">fields</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">field</span><span class="ruby-operator">|</span> <span class="ruby-identifier">field</span>.<span class="ruby-identifier">set_indirect</span>(<span class="ruby-keyword kw">true</span>) <span class="ruby-keyword kw">end</span>
59:       
60:       <span class="ruby-keyword kw">self</span>
61:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000509" class="method-detail">
        <a name="M000509"></a>

        <div class="method-heading">
          <a href="#M000509" class="method-signature">
          <span class="method-name">add_new_revision</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Ends the current <a href="PDF/Revision.html">Revision</a>, and starts a <a
href="PDF.html#M000489">new</a> one.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000509-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000509-source">
<pre>
     <span class="ruby-comment cmt"># File origami/pdf.rb, line 712</span>
712:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add_new_revision</span>
713:       
714:       <span class="ruby-identifier">root</span> = <span class="ruby-ivar">@revisions</span>.<span class="ruby-identifier">last</span>.<span class="ruby-identifier">trailer</span>[<span class="ruby-identifier">:Root</span>] <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@revisions</span>.<span class="ruby-identifier">empty?</span>
715: 
716:       <span class="ruby-ivar">@revisions</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">Revision</span>.<span class="ruby-identifier">new</span>(<span class="ruby-keyword kw">self</span>)
717:       <span class="ruby-ivar">@revisions</span>.<span class="ruby-identifier">last</span>.<span class="ruby-identifier">trailer</span> = <span class="ruby-constant">Trailer</span>.<span class="ruby-identifier">new</span>
718:       <span class="ruby-ivar">@revisions</span>.<span class="ruby-identifier">last</span>.<span class="ruby-identifier">trailer</span>.<span class="ruby-constant">Root</span> = <span class="ruby-identifier">root</span>
719: 
720:       <span class="ruby-keyword kw">self</span>
721:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000504" class="method-detail">
        <a name="M000504"></a>

        <div class="method-heading">
          <a href="#M000504" class="method-signature">
          <span class="method-name">add_to_revision</span><span class="method-args">(object, revision)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Adds a <a href="PDF.html#M000489">new</a> object to a specific revision. If
this object has no version number, then a <a
href="PDF.html#M000489">new</a> one will be automatically computed and
assignated to him. It returns a Reference to this <a
href="Object.html">Object</a>.
</p>
<table>
<tr><td valign="top"><em>object</em>:</td><td>The object to add.

</td></tr>
<tr><td valign="top"><em>revision</em>:</td><td>The revision to add the object to.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000504-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000504-source">
<pre>
     <span class="ruby-comment cmt"># File origami/pdf.rb, line 444</span>
444:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add_to_revision</span>(<span class="ruby-identifier">object</span>, <span class="ruby-identifier">revision</span>)
445:      
446:       <span class="ruby-identifier">object</span>.<span class="ruby-identifier">set_indirect</span>(<span class="ruby-keyword kw">true</span>)
447:       <span class="ruby-identifier">object</span>.<span class="ruby-identifier">set_pdf</span>(<span class="ruby-keyword kw">self</span>)
448:       
449:       <span class="ruby-identifier">object</span>.<span class="ruby-identifier">no</span>, <span class="ruby-identifier">object</span>.<span class="ruby-identifier">generation</span> = <span class="ruby-identifier">alloc_new_object_number</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">object</span>.<span class="ruby-identifier">no</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
450:       
451:       <span class="ruby-identifier">revision</span>.<span class="ruby-identifier">body</span>[<span class="ruby-identifier">object</span>.<span class="ruby-identifier">reference</span>] = <span class="ruby-identifier">object</span>
452:       
453:       <span class="ruby-identifier">object</span>.<span class="ruby-identifier">reference</span>
454:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000505" class="method-detail">
        <a name="M000505"></a>

        <div class="method-heading">
          <a href="#M000505" class="method-signature">
          <span class="method-name">alloc_new_object_number</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns a <a href="PDF.html#M000489">new</a> number/generation for future
object.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000505-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000505-source">
<pre>
     <span class="ruby-comment cmt"># File origami/pdf.rb, line 459</span>
459:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">alloc_new_object_number</span>
460:       
461:       <span class="ruby-identifier">no</span> = <span class="ruby-value">1</span>
462: 
463:       <span class="ruby-comment cmt"># Deprecated number allocation policy (first available)</span>
464:       <span class="ruby-comment cmt">#no = no + 1 while get_object(no)</span>
465: 
466:       <span class="ruby-identifier">objset</span> = <span class="ruby-identifier">indirect_objects</span>.<span class="ruby-identifier">values</span>
467:       <span class="ruby-identifier">indirect_objects</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">find_all</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">obj</span><span class="ruby-operator">|</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">ObjectStream</span>)}.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">objstm</span><span class="ruby-operator">|</span>
468:         <span class="ruby-identifier">objstm</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">obj</span><span class="ruby-operator">|</span> <span class="ruby-identifier">objset</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">obj</span>}
469:       <span class="ruby-keyword kw">end</span>
470: 
471:       <span class="ruby-identifier">allocated</span> = <span class="ruby-identifier">objset</span>.<span class="ruby-identifier">collect</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">obj</span><span class="ruby-operator">|</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">no</span>}.<span class="ruby-identifier">compact</span>
472:       <span class="ruby-identifier">no</span> = <span class="ruby-identifier">allocated</span>.<span class="ruby-identifier">max</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">allocated</span>.<span class="ruby-identifier">empty?</span>
473: 
474:       [ <span class="ruby-identifier">no</span>, <span class="ruby-value">0</span> ]
475:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000520" class="method-detail">
        <a name="M000520"></a>

        <div class="method-heading">
          <a href="#M000520" class="method-signature">
          <span class="method-name">append_page</span><span class="method-args">(page = Page.new, *more)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000520-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000520-source">
<pre>
    <span class="ruby-comment cmt"># File origami/page.rb, line 26</span>
26:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">append_page</span>(<span class="ruby-identifier">page</span> = <span class="ruby-constant">Page</span>.<span class="ruby-identifier">new</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">more</span>)
27:       <span class="ruby-identifier">pages</span> = [ <span class="ruby-identifier">page</span> ].<span class="ruby-identifier">concat</span>(<span class="ruby-identifier">more</span>)
28:       
29:       <span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-node">&quot;Expecting Page type, instead of #{page.class}&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">pages</span>.<span class="ruby-identifier">all?</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">page</span><span class="ruby-operator">|</span> <span class="ruby-identifier">page</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Page</span>)}
30:       
31:       <span class="ruby-identifier">treeroot</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-constant">Pages</span>
32:       
33:       <span class="ruby-identifier">treeroot</span>.<span class="ruby-constant">Kids</span> <span class="ruby-operator">||=</span> [] <span class="ruby-comment cmt">#:nodoc:</span>
34:       <span class="ruby-identifier">treeroot</span>.<span class="ruby-constant">Kids</span>.<span class="ruby-identifier">concat</span>(<span class="ruby-identifier">pages</span>)
35:       <span class="ruby-identifier">treeroot</span>.<span class="ruby-constant">Count</span> = <span class="ruby-identifier">treeroot</span>.<span class="ruby-constant">Kids</span>.<span class="ruby-identifier">length</span>
36:       
37:       <span class="ruby-identifier">pages</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">page</span><span class="ruby-operator">|</span> 
38:         <span class="ruby-identifier">page</span>.<span class="ruby-constant">Parent</span> = <span class="ruby-identifier">treeroot</span>
39:       <span class="ruby-keyword kw">end</span>
40:       
41:       <span class="ruby-keyword kw">self</span>
42:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000500" class="method-detail">
        <a name="M000500"></a>

        <div class="method-heading">
          <a href="#M000500" class="method-signature">
          <span class="method-name">append_subobj</span><span class="method-args">(root, objset, opts)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000500-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000500-source">
<pre>
     <span class="ruby-comment cmt"># File origami/pdf.rb, line 370</span>
370:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">append_subobj</span>(<span class="ruby-identifier">root</span>, <span class="ruby-identifier">objset</span>, <span class="ruby-identifier">opts</span>)
371:         
372:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">objset</span>.<span class="ruby-identifier">find</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">o</span><span class="ruby-operator">|</span> <span class="ruby-identifier">root</span>.<span class="ruby-identifier">equal?</span>(<span class="ruby-identifier">o</span>) }.<span class="ruby-identifier">nil?</span>
373:           <span class="ruby-identifier">objset</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">root</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:only_keys</span>]
374: 
375:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">root</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Dictionary</span>)
376:             <span class="ruby-identifier">root</span>.<span class="ruby-identifier">each_pair</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">name</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
377:               <span class="ruby-identifier">objset</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">name</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:only_keys</span>]
378: 
379:               <span class="ruby-identifier">append_subobj</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">objset</span>, <span class="ruby-identifier">opts</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:include_keys</span>] <span class="ruby-keyword kw">and</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:only_keys</span>]
380:               <span class="ruby-identifier">append_subobj</span>(<span class="ruby-identifier">value</span>, <span class="ruby-identifier">objset</span>, <span class="ruby-identifier">opts</span>)
381:             }
382:           <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">root</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>) <span class="ruby-keyword kw">or</span> (<span class="ruby-identifier">root</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">ObjectStream</span>) <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:include_objectstreams</span>])
383:             <span class="ruby-identifier">root</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">subobj</span><span class="ruby-operator">|</span> <span class="ruby-identifier">append_subobj</span>(<span class="ruby-identifier">subobj</span>, <span class="ruby-identifier">objset</span>, <span class="ruby-identifier">opts</span>) }
384:           <span class="ruby-keyword kw">end</span>
385:         <span class="ruby-keyword kw">end</span>
386:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000475" class="method-detail">
        <a name="M000475"></a>

        <div class="method-heading">
          <a href="#M000475" class="method-signature">
          <span class="method-name">attach_file</span><span class="method-args">(path, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Attachs an embedded file to the <a href="PDF.html">PDF</a>.
</p>
<table>
<tr><td valign="top"><em>path</em>:</td><td>The path to the file to attach.

</td></tr>
<tr><td valign="top"><em>options</em>:</td><td>A set of options to configure the attachment.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000475-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000475-source">
<pre>
    <span class="ruby-comment cmt"># File origami/file.rb, line 35</span>
35:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">attach_file</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">options</span> = {})
36: 
37:       <span class="ruby-comment cmt">#</span>
38:       <span class="ruby-comment cmt"># Default options.</span>
39:       <span class="ruby-comment cmt">#</span>
40:       <span class="ruby-identifier">params</span> = 
41:       {
42:         <span class="ruby-identifier">:Register</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">true</span>,                      <span class="ruby-comment cmt"># Shall the file be registered in the name directory ?</span>
43:         <span class="ruby-identifier">:EmbeddedName</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">basename</span>(<span class="ruby-identifier">path</span>),   <span class="ruby-comment cmt"># The inner filename of the attachment.</span>
44:         <span class="ruby-identifier">:Filter</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:FlateDecode</span>                 <span class="ruby-comment cmt"># The stream filter used to store data.</span>
45:       }
46: 
47:       <span class="ruby-identifier">params</span>.<span class="ruby-identifier">update</span>(<span class="ruby-identifier">options</span>)
48:       
49:       <span class="ruby-identifier">fdata</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">path</span>, <span class="ruby-value str">&quot;r&quot;</span>).<span class="ruby-identifier">binmode</span>.<span class="ruby-identifier">read</span>
50:       
51:       <span class="ruby-identifier">fstream</span> = <span class="ruby-constant">EmbeddedFileStream</span>.<span class="ruby-identifier">new</span>
52:       <span class="ruby-identifier">fstream</span>.<span class="ruby-identifier">data</span> = <span class="ruby-identifier">fdata</span>
53:       <span class="ruby-identifier">fstream</span>.<span class="ruby-identifier">setFilter</span>(<span class="ruby-identifier">params</span>[<span class="ruby-identifier">:Filter</span>])
54:       
55:       <span class="ruby-identifier">name</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:EmbeddedName</span>]
56:       <span class="ruby-identifier">fspec</span> = <span class="ruby-constant">FileSpec</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">setType</span>(<span class="ruby-identifier">:Filespec</span>).<span class="ruby-identifier">setF</span>(<span class="ruby-identifier">name</span>).<span class="ruby-identifier">setEF</span>(<span class="ruby-constant">FileSpec</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">:F</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">fstream</span>))
57:       
58:       <span class="ruby-identifier">register</span>(<span class="ruby-constant">Names</span><span class="ruby-operator">::</span><span class="ruby-constant">Root</span><span class="ruby-operator">::</span><span class="ruby-constant">EMBEDDEDFILES</span>, <span class="ruby-identifier">name</span>, <span class="ruby-identifier">fspec</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:Register</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span>
59: 
60:       <span class="ruby-identifier">fspec</span>
61:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000506" class="method-detail">
        <a name="M000506"></a>

        <div class="method-heading">
          <a href="#M000506" class="method-signature">
          <span class="method-name">compile</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
This method is meant to recompute, verify and correct main <a
href="PDF.html">PDF</a> structures, in order to output a proper file.
</p>
<ul>
<li>Allocates <a href="PDF.html#M000499">objects</a> references.

</li>
<li>Sets some <a href="PDF.html#M000499">objects</a> missing required values.

</li>
</ul>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000506-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000506-source">
<pre>
     <span class="ruby-comment cmt"># File origami/pdf.rb, line 482</span>
482:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">compile</span>
483:       
484:       <span class="ruby-comment cmt">#</span>
485:       <span class="ruby-comment cmt"># A valid document must have at least one page.</span>
486:       <span class="ruby-comment cmt">#</span>
487:       <span class="ruby-identifier">append_page</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">pages</span>.<span class="ruby-identifier">empty?</span>
488:      
489:       <span class="ruby-comment cmt">#</span>
490:       <span class="ruby-comment cmt"># Allocates object numbers and creates references.</span>
491:       <span class="ruby-comment cmt"># Invokes object finalization methods.</span>
492:       <span class="ruby-comment cmt">#</span>
493:       <span class="ruby-identifier">physicalize</span>
494:             
495:       <span class="ruby-comment cmt">#</span>
496:       <span class="ruby-comment cmt"># Sets the PDF version header.</span>
497:       <span class="ruby-comment cmt">#</span>
498:       <span class="ruby-identifier">version</span>, <span class="ruby-identifier">level</span> = <span class="ruby-identifier">version_required</span>
499:       <span class="ruby-ivar">@header</span>.<span class="ruby-identifier">majorversion</span> = <span class="ruby-identifier">version</span>[<span class="ruby-value">0</span>,<span class="ruby-value">1</span>].<span class="ruby-identifier">to_i</span>
500:       <span class="ruby-ivar">@header</span>.<span class="ruby-identifier">minorversion</span> = <span class="ruby-identifier">version</span>[<span class="ruby-value">2</span>,<span class="ruby-value">1</span>].<span class="ruby-identifier">to_i</span>
501: 
502:       <span class="ruby-identifier">set_extension_level</span>(<span class="ruby-identifier">version</span>, <span class="ruby-identifier">level</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">level</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span>
503:       
504:       <span class="ruby-keyword kw">self</span>
505:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000477" class="method-detail">
        <a name="M000477"></a>

        <div class="method-heading">
          <a href="#M000477" class="method-signature">
          <span class="method-name">create_acroform</span><span class="method-args">(*fields)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Creates a <a href="PDF.html#M000489">new</a> AcroForm with specified
fields.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000477-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000477-source">
<pre>
    <span class="ruby-comment cmt"># File origami/acroform.rb, line 40</span>
40:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create_acroform</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">fields</span>)
41:       <span class="ruby-identifier">acroform</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-constant">AcroForm</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">InteractiveForm</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">set_indirect</span>(<span class="ruby-keyword kw">true</span>)
42:       <span class="ruby-identifier">add_fields</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">fields</span>)
43: 
44:       <span class="ruby-identifier">acroform</span>
45:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000482" class="method-detail">
        <a name="M000482"></a>

        <div class="method-heading">
          <a href="#M000482" class="method-signature">
          <span class="method-name">create_xfa_form</span><span class="method-args">(xdp, *fields)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000482-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000482-source">
<pre>
    <span class="ruby-comment cmt"># File origami/xfa.rb, line 32</span>
32:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">create_xfa_form</span>(<span class="ruby-identifier">xdp</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">fields</span>)
33:       <span class="ruby-identifier">acroform</span> = <span class="ruby-identifier">create_acroform</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">fields</span>)
34:       <span class="ruby-identifier">acroform</span>.<span class="ruby-constant">XFA</span> = <span class="ruby-constant">Stream</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">xdp</span>, <span class="ruby-identifier">:Filter</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:FlateDecode</span>)
35: 
36:       <span class="ruby-identifier">acroform</span>
37:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000480" class="method-detail">
        <a name="M000480"></a>

        <div class="method-heading">
          <a href="#M000480" class="method-signature">
          <span class="method-name">decrypt</span><span class="method-args">(passwd = &quot;&quot;)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Decrypts the current document (only RC4 40..128 bits). TODO: AESv2, AESv3,
lazy decryption
</p>
<table>
<tr><td valign="top"><em>passwd</em>:</td><td>The password to <a href="PDF.html#M000480">decrypt</a> the document.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000480-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000480-source">
<pre>
     <span class="ruby-comment cmt"># File origami/encryption.rb, line 54</span>
 54:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">decrypt</span>(<span class="ruby-identifier">passwd</span> = <span class="ruby-value str">&quot;&quot;</span>)
 55:     
 56:       <span class="ruby-keyword kw">unless</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">is_encrypted?</span>
 57:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">EncryptionError</span>, <span class="ruby-value str">&quot;PDF is not encrypted&quot;</span>
 58:       <span class="ruby-keyword kw">end</span>
 59:      
 60:       <span class="ruby-identifier">encrypt_dict</span> = <span class="ruby-identifier">get_doc_attr</span>(<span class="ruby-identifier">:Encrypt</span>)
 61:       <span class="ruby-identifier">handler</span> = <span class="ruby-constant">Encryption</span><span class="ruby-operator">::</span><span class="ruby-constant">Standard</span><span class="ruby-operator">::</span><span class="ruby-constant">Dictionary</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">encrypt_dict</span>.<span class="ruby-identifier">copy</span>)
 62: 
 63:       <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">handler</span>.<span class="ruby-constant">Filter</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">:Standard</span>
 64:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">EncryptionNotSupportedError</span>, <span class="ruby-node">&quot;Unknown security handler : '#{handler.Filter.to_s}'&quot;</span>
 65:       <span class="ruby-keyword kw">end</span>
 66: 
 67:       <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">handler</span>.<span class="ruby-constant">V</span>.<span class="ruby-identifier">to_i</span>
 68:         <span class="ruby-keyword kw">when</span> <span class="ruby-value">1</span>,<span class="ruby-value">2</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">str_algo</span> = <span class="ruby-identifier">stm_algo</span> = <span class="ruby-constant">Encryption</span><span class="ruby-operator">::</span><span class="ruby-constant">ARC4</span>
 69:         <span class="ruby-keyword kw">when</span> <span class="ruby-value">4</span>
 70:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">handler</span>[<span class="ruby-identifier">:CF</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Dictionary</span>)
 71:             <span class="ruby-identifier">cfs</span> = <span class="ruby-identifier">handler</span>[<span class="ruby-identifier">:CF</span>]
 72:             
 73:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">handler</span>[<span class="ruby-identifier">:StrF</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Name</span>) <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">cfs</span>[<span class="ruby-identifier">handler</span>[<span class="ruby-identifier">:StrF</span>]].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Dictionary</span>)
 74:               <span class="ruby-identifier">cfdict</span> = <span class="ruby-identifier">cfs</span>[<span class="ruby-identifier">handler</span>[<span class="ruby-identifier">:StrF</span>]]
 75:               
 76:               <span class="ruby-identifier">str_algo</span> =
 77:               <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">cfdict</span>[<span class="ruby-identifier">:CFM</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">:V2</span> <span class="ruby-keyword kw">then</span> <span class="ruby-constant">Encryption</span><span class="ruby-operator">::</span><span class="ruby-constant">ARC4</span>
 78:               <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">cfdict</span>[<span class="ruby-identifier">:CFM</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">:AESV2</span> <span class="ruby-keyword kw">then</span> <span class="ruby-constant">Encryption</span><span class="ruby-operator">::</span><span class="ruby-constant">AES</span>
 79:               <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">cfdict</span>[<span class="ruby-identifier">:CFM</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">:None</span> <span class="ruby-keyword kw">then</span> <span class="ruby-constant">Encryption</span><span class="ruby-operator">::</span><span class="ruby-constant">Identity</span>
 80:               <span class="ruby-keyword kw">else</span>
 81:                 <span class="ruby-constant">Encryption</span><span class="ruby-operator">::</span><span class="ruby-constant">Identity</span>
 82:               <span class="ruby-keyword kw">end</span>
 83:             <span class="ruby-keyword kw">else</span>
 84:               <span class="ruby-identifier">str_algo</span> = <span class="ruby-constant">Encryption</span><span class="ruby-operator">::</span><span class="ruby-constant">Identity</span>
 85:             <span class="ruby-keyword kw">end</span>
 86: 
 87:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">handler</span>[<span class="ruby-identifier">:StmF</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Name</span>) <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">cfs</span>[<span class="ruby-identifier">handler</span>[<span class="ruby-identifier">:StmF</span>]].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Dictionary</span>)
 88:               <span class="ruby-identifier">cfdict</span> = <span class="ruby-identifier">cfs</span>[<span class="ruby-identifier">handler</span>[<span class="ruby-identifier">:StmF</span>]]
 89: 
 90:               <span class="ruby-identifier">stm_algo</span> =
 91:               <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">cfdict</span>[<span class="ruby-identifier">:CFM</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">:V2</span> <span class="ruby-keyword kw">then</span> <span class="ruby-constant">Encryption</span><span class="ruby-operator">::</span><span class="ruby-constant">ARC4</span>
 92:               <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">cfdict</span>[<span class="ruby-identifier">:CFM</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">:AESV2</span> <span class="ruby-keyword kw">then</span> <span class="ruby-constant">Encryption</span><span class="ruby-operator">::</span><span class="ruby-constant">AES</span>
 93:               <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">cfdict</span>[<span class="ruby-identifier">:CFM</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">:None</span> <span class="ruby-keyword kw">then</span> <span class="ruby-constant">Encryption</span><span class="ruby-operator">::</span><span class="ruby-constant">Identity</span>
 94:               <span class="ruby-keyword kw">else</span>
 95:                 <span class="ruby-constant">Encryption</span><span class="ruby-operator">::</span><span class="ruby-constant">Identity</span>
 96:               <span class="ruby-keyword kw">end</span>
 97:             <span class="ruby-keyword kw">else</span>
 98:               <span class="ruby-identifier">stm_algo</span> = <span class="ruby-constant">Encryption</span><span class="ruby-operator">::</span><span class="ruby-constant">Identity</span>
 99:             <span class="ruby-keyword kw">end</span>
100: 
101:           <span class="ruby-keyword kw">else</span>
102:             <span class="ruby-identifier">str_algo</span> = <span class="ruby-identifier">stm_algo</span> = <span class="ruby-constant">Encryption</span><span class="ruby-operator">::</span><span class="ruby-constant">Identity</span>
103:           <span class="ruby-keyword kw">end</span>
104:       <span class="ruby-keyword kw">else</span>
105:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">EncryptionNotSupportedError</span>, <span class="ruby-node">&quot;Unsupported encryption version : #{handler.V}&quot;</span>
106:       <span class="ruby-keyword kw">end</span>
107: 
108:       <span class="ruby-identifier">id</span> = <span class="ruby-identifier">get_doc_attr</span>(<span class="ruby-identifier">:ID</span>)
109:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">id</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">id</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>)
110:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">EncryptionError</span>, <span class="ruby-value str">&quot;Document ID was not found or is invalid&quot;</span>
111:       <span class="ruby-keyword kw">else</span>
112:         <span class="ruby-identifier">id</span> = <span class="ruby-identifier">id</span>.<span class="ruby-identifier">first</span>
113:       <span class="ruby-keyword kw">end</span>
114: 
115:       <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">is_owner_password?</span>(<span class="ruby-identifier">passwd</span>, <span class="ruby-identifier">id</span>) <span class="ruby-keyword kw">and</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">is_user_password?</span>(<span class="ruby-identifier">passwd</span>, <span class="ruby-identifier">id</span>)
116:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">EncryptionInvalidPasswordError</span>
117:       <span class="ruby-keyword kw">end</span>
118: 
119:       <span class="ruby-identifier">encryption_key</span> = <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">compute_encryption_key</span>(<span class="ruby-identifier">passwd</span>, <span class="ruby-identifier">id</span>)
120: 
121:       <span class="ruby-comment cmt">#self.extend(Encryption::EncryptedDocument)</span>
122:       <span class="ruby-comment cmt">#self.encryption_dict = encrypt_dict</span>
123:       <span class="ruby-comment cmt">#self.encryption_key = encryption_key</span>
124:       <span class="ruby-comment cmt">#self.stm_algo = self.str_algo = algorithm</span>
125: 
126:       <span class="ruby-identifier">encrypt_metadata</span> = (<span class="ruby-identifier">handler</span>.<span class="ruby-constant">EncryptMetadata</span> <span class="ruby-operator">!=</span> <span class="ruby-keyword kw">false</span>)
127: 
128:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">extend</span>(<span class="ruby-constant">Encryption</span><span class="ruby-operator">::</span><span class="ruby-constant">EncryptedDocument</span>)
129:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">encryption_dict</span> = <span class="ruby-identifier">handler</span>
130:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">encryption_key</span> = <span class="ruby-identifier">encryption_key</span>
131:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">stm_algo</span>,<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">str_algo</span> = <span class="ruby-identifier">stm_algo</span>,<span class="ruby-identifier">str_algo</span>
132:       
133:       <span class="ruby-comment cmt">#</span>
134:       <span class="ruby-comment cmt"># Should be fixed to exclude only the active XRefStream</span>
135:       <span class="ruby-comment cmt">#</span>
136:       <span class="ruby-identifier">ind_objects</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">all_indirect_objects</span>
137:       <span class="ruby-identifier">metadata</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-constant">Metadata</span>
138: 
139:       <span class="ruby-identifier">ind_objects</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">indobj</span>,<span class="ruby-identifier">rev</span><span class="ruby-operator">|</span>
140:         <span class="ruby-identifier">encrypted_objects</span> = []
141:         <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">indobj</span>
142:           <span class="ruby-keyword kw">when</span> <span class="ruby-constant">String</span>,<span class="ruby-constant">Stream</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">encrypted_objects</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">indobj</span>
143:           <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Dictionary</span>,<span class="ruby-constant">Array</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">encrypted_objects</span> <span class="ruby-operator">|=</span> <span class="ruby-identifier">indobj</span>.<span class="ruby-identifier">strings_cache</span>
144:         <span class="ruby-keyword kw">end</span>
145: 
146:         <span class="ruby-identifier">encrypted_objects</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">obj</span><span class="ruby-operator">|</span>
147:           <span class="ruby-identifier">parent</span> = <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">indirect_parent</span>
148:           <span class="ruby-identifier">no</span>, <span class="ruby-identifier">gen</span> = <span class="ruby-identifier">parent</span>.<span class="ruby-identifier">no</span>, <span class="ruby-identifier">parent</span>.<span class="ruby-identifier">generation</span>
149: 
150:           <span class="ruby-identifier">k</span> = <span class="ruby-identifier">encryption_key</span> <span class="ruby-operator">+</span> [<span class="ruby-identifier">no</span>].<span class="ruby-identifier">pack</span>(<span class="ruby-value str">&quot;I&quot;</span>)[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">2</span>] <span class="ruby-operator">+</span> [<span class="ruby-identifier">gen</span>].<span class="ruby-identifier">pack</span>(<span class="ruby-value str">&quot;I&quot;</span>)[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">1</span>]
151:           <span class="ruby-identifier">key_len</span> = (<span class="ruby-identifier">k</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">16</span>) <span class="ruby-operator">?</span> <span class="ruby-value">16</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">k</span>.<span class="ruby-identifier">length</span>
152: 
153:           <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">obj</span>
154:             <span class="ruby-keyword kw">when</span> <span class="ruby-constant">String</span>
155:               <span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">equal?</span>(<span class="ruby-identifier">encrypt_dict</span>[<span class="ruby-identifier">:U</span>]) <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">equal?</span>(<span class="ruby-identifier">encrypt_dict</span>[<span class="ruby-identifier">:O</span>])
156:               <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">extend</span>(<span class="ruby-constant">Encryption</span><span class="ruby-operator">::</span><span class="ruby-constant">EncryptedString</span>)
157:               <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">encryption_key</span> = <span class="ruby-identifier">encryption_key</span>
158:               <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">algorithm</span> = <span class="ruby-identifier">stm_algo</span>
159:               <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">decrypted</span> = <span class="ruby-keyword kw">false</span>
160:               <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">decrypt!</span>
161: 
162:             <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Stream</span>
163:               <span class="ruby-keyword kw">next</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">XRefStream</span>) <span class="ruby-keyword kw">or</span> (<span class="ruby-keyword kw">not</span> <span class="ruby-identifier">encrypt_metadata</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">equal?</span>(<span class="ruby-identifier">metadata</span>))
164:               <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">extend</span>(<span class="ruby-constant">Encryption</span><span class="ruby-operator">::</span><span class="ruby-constant">EncryptedStream</span>)
165:               <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">encryption_key</span> = <span class="ruby-identifier">encryption_key</span>
166:               <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">algorithm</span> = <span class="ruby-identifier">stm_algo</span>
167:               <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">decrypted</span> = <span class="ruby-keyword kw">false</span>
168:           <span class="ruby-keyword kw">end</span>
169: 
170:         <span class="ruby-keyword kw">end</span>
171:       <span class="ruby-keyword kw">end</span>
172: 
173:       <span class="ruby-keyword kw">self</span>
174:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000511" class="method-detail">
        <a name="M000511"></a>

        <div class="method-heading">
          <a href="#M000511" class="method-signature">
          <span class="method-name">delete_object</span><span class="method-args">(no, generation = 0)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Remove an object.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000511-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000511-source">
<pre>
     <span class="ruby-comment cmt"># File origami/pdf.rb, line 750</span>
750:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete_object</span>(<span class="ruby-identifier">no</span>, <span class="ruby-identifier">generation</span> = <span class="ruby-value">0</span>)
751:       
752:       <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">no</span>
753:         <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Reference</span>
754:           <span class="ruby-identifier">target</span> = <span class="ruby-identifier">no</span>
755:         <span class="ruby-keyword kw">when</span> <span class="ruby-operator">::</span><span class="ruby-constant">Integer</span>
756:           <span class="ruby-identifier">target</span> = <span class="ruby-constant">Reference</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">no</span>, <span class="ruby-identifier">generation</span>)
757:       <span class="ruby-keyword kw">else</span>
758:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-node">&quot;Invalid parameter type : #{no.class}&quot;</span> 
759:       <span class="ruby-keyword kw">end</span>
760:       
761:       <span class="ruby-ivar">@revisions</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">rev</span><span class="ruby-operator">|</span>
762:         <span class="ruby-identifier">rev</span>.<span class="ruby-identifier">body</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">target</span>)
763:       <span class="ruby-keyword kw">end</span>
764: 
765:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000526" class="method-detail">
        <a name="M000526"></a>

        <div class="method-heading">
          <a href="#M000526" class="method-signature">
          <span class="method-name">delete_xrefstm</span><span class="method-args">(xrefstm)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000526-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000526-source">
<pre>
    <span class="ruby-comment cmt"># File origami/xreftable.rb, line 30</span>
30:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete_xrefstm</span>(<span class="ruby-identifier">xrefstm</span>)
31:         <span class="ruby-identifier">prev</span> = <span class="ruby-identifier">xrefstm</span>.<span class="ruby-constant">Prev</span>
32:         <span class="ruby-identifier">delete_object</span>(<span class="ruby-identifier">xrefstm</span>.<span class="ruby-identifier">reference</span>)
33: 
34:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">prev</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Integer</span>) <span class="ruby-keyword kw">and</span> (<span class="ruby-identifier">prev_stm</span> = <span class="ruby-identifier">get_object_by_offset</span>(<span class="ruby-identifier">prev</span>)).<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">XRefStream</span>)
35:           <span class="ruby-identifier">delete_xrefstm</span>(<span class="ruby-identifier">prev_stm</span>)
36:         <span class="ruby-keyword kw">end</span>
37:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000528" class="method-detail">
        <a name="M000528"></a>

        <div class="method-heading">
          <a href="#M000528" class="method-signature">
          <span class="method-name">delinearize!</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Tries to delinearize the document if it has been linearized. This operation
is xrefs destructive, should be fixed in the future to merge tables.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000528-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000528-source">
<pre>
    <span class="ruby-comment cmt"># File origami/linearization.rb, line 47</span>
47:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delinearize!</span>
48:       <span class="ruby-identifier">raise</span> <span class="ruby-constant">RuntimeError</span>, <span class="ruby-value str">'Not a linearized document'</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">is_linearized?</span>
49:       
50:       <span class="ruby-comment cmt">#</span>
51:       <span class="ruby-comment cmt"># Saves the catalog location.</span>
52:       <span class="ruby-comment cmt">#</span>
53:       <span class="ruby-identifier">catalog_ref</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-identifier">reference</span>
54: 
55:       <span class="ruby-identifier">lin_dict</span> = <span class="ruby-ivar">@revisions</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">body</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">first</span>
56:       <span class="ruby-identifier">hints</span> = <span class="ruby-identifier">lin_dict</span>[<span class="ruby-identifier">:H</span>]
57:   
58:       <span class="ruby-comment cmt">#</span>
59:       <span class="ruby-comment cmt"># Removes hint streams used by linearization.</span>
60:       <span class="ruby-comment cmt">#</span>
61:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">hints</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-operator">::</span><span class="ruby-constant">Array</span>)
62:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">hints</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">hints</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Integer</span>)
63:           <span class="ruby-identifier">hint_stream</span> = <span class="ruby-identifier">get_object_by_offset</span>(<span class="ruby-identifier">hints</span>[<span class="ruby-value">0</span>])
64:           <span class="ruby-identifier">delete_object</span>(<span class="ruby-identifier">hint_stream</span>.<span class="ruby-identifier">reference</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">hint_stream</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Stream</span>)
65:         <span class="ruby-keyword kw">end</span>
66: 
67:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">hints</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">2</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">hints</span>[<span class="ruby-value">2</span>].<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Integer</span>)
68:           <span class="ruby-identifier">overflow_stream</span> = <span class="ruby-identifier">get_object_by_offset</span>(<span class="ruby-identifier">hints</span>[<span class="ruby-value">2</span>])
69:           <span class="ruby-identifier">delete_object</span>(<span class="ruby-identifier">overflow_stream</span>.<span class="ruby-identifier">reference</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">overflow_stream</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Stream</span>)
70:         <span class="ruby-keyword kw">end</span>
71:       <span class="ruby-keyword kw">end</span>
72: 
73:       <span class="ruby-comment cmt">#</span>
74:       <span class="ruby-comment cmt"># Fix: Should be merged instead.</span>
75:       <span class="ruby-comment cmt">#</span>
76:       <span class="ruby-identifier">remove_xrefs</span>
77: 
78:       <span class="ruby-comment cmt">#</span>
79:       <span class="ruby-comment cmt"># Remove the linearization revision.</span>
80:       <span class="ruby-comment cmt">#</span>
81:       <span class="ruby-identifier">remove_revision</span>(<span class="ruby-value">0</span>)
82: 
83:       <span class="ruby-comment cmt">#</span>
84:       <span class="ruby-comment cmt"># Restore the Catalog.</span>
85:       <span class="ruby-comment cmt">#</span>
86:       <span class="ruby-ivar">@revisions</span>.<span class="ruby-identifier">last</span>.<span class="ruby-identifier">trailer</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">Trailer</span>.<span class="ruby-identifier">new</span>
87:       <span class="ruby-ivar">@revisions</span>.<span class="ruby-identifier">last</span>.<span class="ruby-identifier">trailer</span>.<span class="ruby-identifier">dictionary</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">Dictionary</span>.<span class="ruby-identifier">new</span>
88:       <span class="ruby-ivar">@revisions</span>.<span class="ruby-identifier">last</span>.<span class="ruby-identifier">trailer</span>.<span class="ruby-identifier">dictionary</span>[<span class="ruby-identifier">:Root</span>] = <span class="ruby-identifier">catalog_ref</span>
89: 
90:       <span class="ruby-keyword kw">self</span>
91:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000531" class="method-detail">
        <a name="M000531"></a>

        <div class="method-heading">
          <a href="#M000531" class="method-signature">
          <span class="method-name">enable_usage_rights</span><span class="method-args">(*rights)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Enable the document Usage Rights.
</p>
<table>
<tr><td valign="top"><em>rights</em>:</td><td>list of rights defined in <a
href="UsageRights/Rights.html">UsageRights::Rights</a>

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000531-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000531-source">
<pre>
     <span class="ruby-comment cmt"># File origami/signature.rb, line 130</span>
130:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">enable_usage_rights</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">rights</span>)
131:       
132:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">signfield_size</span>(<span class="ruby-identifier">certificate</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">ca</span> = []) <span class="ruby-comment cmt">#:nodoc:</span>
133:         <span class="ruby-identifier">datatest</span> = <span class="ruby-value str">&quot;abcdefghijklmnopqrstuvwxyz&quot;</span>
134:         <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKCS7</span>.<span class="ruby-identifier">sign</span>(<span class="ruby-identifier">certificate</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">datatest</span>, <span class="ruby-identifier">ca</span>, <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKCS7</span><span class="ruby-operator">::</span><span class="ruby-constant">DETACHED</span> <span class="ruby-operator">|</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKCS7</span><span class="ruby-operator">::</span><span class="ruby-constant">BINARY</span>).<span class="ruby-identifier">to_der</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">+</span> <span class="ruby-value">128</span>
135:       <span class="ruby-keyword kw">end</span>
136:       
137:       <span class="ruby-keyword kw">begin</span>
138:         <span class="ruby-identifier">key</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">RSA</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-value str">'adobe.key'</span>,<span class="ruby-value str">'r'</span>).<span class="ruby-identifier">binmode</span>.<span class="ruby-identifier">read</span>)
139:         <span class="ruby-identifier">certificate</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">X509</span><span class="ruby-operator">::</span><span class="ruby-constant">Certificate</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-value str">'adobe.crt'</span>,<span class="ruby-value str">'r'</span>).<span class="ruby-identifier">binmode</span>.<span class="ruby-identifier">read</span>)
140:       <span class="ruby-keyword kw">rescue</span>
141:         <span class="ruby-identifier">warn</span> <span class="ruby-value str">&quot;The Adobe private key is necessary to enable usage rights.\nYou do not seem to be Adobe :)... Aborting.&quot;</span>
142:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
143:       <span class="ruby-keyword kw">end</span>
144:       
145:       <span class="ruby-identifier">digsig</span> = <span class="ruby-constant">Signature</span><span class="ruby-operator">::</span><span class="ruby-constant">DigitalSignature</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">set_indirect</span>(<span class="ruby-keyword kw">true</span>)
146:       
147:       <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-constant">AcroForm</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">InteractiveForm</span>.<span class="ruby-identifier">new</span>
148:       <span class="ruby-comment cmt">#self.Catalog.AcroForm.SigFlags = InteractiveForm::SigFlags::APPENDONLY</span>
149:       
150:       <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">Type</span> = <span class="ruby-identifier">:Sig</span> <span class="ruby-comment cmt">#:nodoc:</span>
151:       <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">Contents</span> = <span class="ruby-constant">HexaString</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">&quot;\x00&quot;</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">signfield_size</span>(<span class="ruby-identifier">certificate</span>, <span class="ruby-identifier">key</span>, [])) <span class="ruby-comment cmt">#:nodoc:</span>
152:       <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">Filter</span> = <span class="ruby-constant">Name</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">&quot;Adobe.PPKLite&quot;</span>) <span class="ruby-comment cmt">#:nodoc:</span>
153:       <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">Name</span> = <span class="ruby-value str">&quot;ARE Acrobat Product v8.0 P23 0002337&quot;</span> <span class="ruby-comment cmt">#:nodoc:</span>
154:       <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">SubFilter</span> = <span class="ruby-constant">Name</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">&quot;adbe.pkcs7.detached&quot;</span>) <span class="ruby-comment cmt">#:nodoc:</span>
155:       <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">ByteRange</span> = [<span class="ruby-value">0</span>, <span class="ruby-value">0</span>, <span class="ruby-value">0</span>, <span class="ruby-value">0</span>] <span class="ruby-comment cmt">#:nodoc:</span>
156:       
157:       <span class="ruby-identifier">sigref</span> = <span class="ruby-constant">Signature</span><span class="ruby-operator">::</span><span class="ruby-constant">Reference</span>.<span class="ruby-identifier">new</span> <span class="ruby-comment cmt">#:nodoc:</span>
158:       <span class="ruby-identifier">sigref</span>.<span class="ruby-constant">Type</span> = <span class="ruby-identifier">:SigRef</span> <span class="ruby-comment cmt">#:nodoc:</span>
159:       <span class="ruby-identifier">sigref</span>.<span class="ruby-constant">TransformMethod</span> = <span class="ruby-identifier">:UR3</span> <span class="ruby-comment cmt">#:nodoc:</span>
160:       <span class="ruby-identifier">sigref</span>.<span class="ruby-constant">Data</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>
161:       
162:       <span class="ruby-identifier">sigref</span>.<span class="ruby-constant">TransformParams</span> = <span class="ruby-constant">UsageRights</span><span class="ruby-operator">::</span><span class="ruby-constant">TransformParams</span>.<span class="ruby-identifier">new</span>
163:       <span class="ruby-identifier">sigref</span>.<span class="ruby-constant">TransformParams</span>.<span class="ruby-constant">P</span> = <span class="ruby-keyword kw">true</span> <span class="ruby-comment cmt">#:nodoc:</span>
164:       <span class="ruby-identifier">sigref</span>.<span class="ruby-constant">TransformParams</span>.<span class="ruby-constant">Type</span> = <span class="ruby-identifier">:TransformParams</span> <span class="ruby-comment cmt">#:nodoc:</span>
165:       <span class="ruby-identifier">sigref</span>.<span class="ruby-constant">TransformParams</span>.<span class="ruby-constant">V</span> = <span class="ruby-constant">UsageRights</span><span class="ruby-operator">::</span><span class="ruby-constant">TransformParams</span><span class="ruby-operator">::</span><span class="ruby-constant">VERSION</span>
166:       
167:       <span class="ruby-identifier">rights</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">right</span><span class="ruby-operator">|</span>
168:         
169:         <span class="ruby-identifier">sigref</span>.<span class="ruby-constant">TransformParams</span>[<span class="ruby-identifier">right</span>.<span class="ruby-identifier">first</span>] <span class="ruby-operator">||=</span> []
170:         <span class="ruby-identifier">sigref</span>.<span class="ruby-constant">TransformParams</span>[<span class="ruby-identifier">right</span>.<span class="ruby-identifier">first</span>].<span class="ruby-identifier">concat</span>(<span class="ruby-identifier">right</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>])
171:         
172:       }
173:       
174:       <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">Reference</span> = [ <span class="ruby-identifier">sigref</span> ]
175:       
176:       <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-constant">Perms</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">Perms</span>.<span class="ruby-identifier">new</span>
177:       <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-constant">Perms</span>.<span class="ruby-constant">UR3</span> = <span class="ruby-identifier">digsig</span>
178:       
179:       <span class="ruby-comment cmt">#</span>
180:       <span class="ruby-comment cmt">#  Flattening the PDF to get file view.</span>
181:       <span class="ruby-comment cmt">#</span>
182:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">compile</span>
183:       
184:       <span class="ruby-comment cmt">#</span>
185:       <span class="ruby-comment cmt"># Creating an empty Xref table to compute signature byte range.</span>
186:       <span class="ruby-comment cmt">#</span>
187:       <span class="ruby-identifier">rebuild_dummy_xrefs</span>
188:       
189:       <span class="ruby-identifier">sigoffset</span> = <span class="ruby-identifier">get_object_offset</span>(<span class="ruby-identifier">digsig</span>.<span class="ruby-identifier">no</span>, <span class="ruby-identifier">digsig</span>.<span class="ruby-identifier">generation</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">digsig</span>.<span class="ruby-identifier">sigOffset</span>
190:       
191:       <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">ByteRange</span>[<span class="ruby-value">0</span>] = <span class="ruby-value">0</span> 
192:       <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">ByteRange</span>[<span class="ruby-value">1</span>] = <span class="ruby-identifier">sigoffset</span>
193:       <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">ByteRange</span>[<span class="ruby-value">2</span>] = <span class="ruby-identifier">sigoffset</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">Contents</span>.<span class="ruby-identifier">size</span>
194:       
195:       <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">ByteRange</span>[<span class="ruby-value">3</span>] = <span class="ruby-identifier">filesize</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">ByteRange</span>[<span class="ruby-value">2</span>] <span class="ruby-keyword kw">until</span> <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">ByteRange</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">filesize</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">ByteRange</span>[<span class="ruby-value">2</span>]
196:       
197:       <span class="ruby-comment cmt"># From that point the file size remains constant</span>
198:       
199:       <span class="ruby-comment cmt">#</span>
200:       <span class="ruby-comment cmt"># Correct Xrefs variations caused by ByteRange modifications.</span>
201:       <span class="ruby-comment cmt">#</span>
202:       <span class="ruby-identifier">rebuildxrefs</span>
203:       
204:       <span class="ruby-identifier">filedata</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_bin</span>
205:       <span class="ruby-identifier">signable_data</span> = <span class="ruby-identifier">filedata</span>[<span class="ruby-identifier">digsig</span>.<span class="ruby-constant">ByteRange</span>[<span class="ruby-value">0</span>],<span class="ruby-identifier">digsig</span>.<span class="ruby-constant">ByteRange</span>[<span class="ruby-value">1</span>]] <span class="ruby-operator">+</span> <span class="ruby-identifier">filedata</span>[<span class="ruby-identifier">digsig</span>.<span class="ruby-constant">ByteRange</span>[<span class="ruby-value">2</span>],<span class="ruby-identifier">digsig</span>.<span class="ruby-constant">ByteRange</span>[<span class="ruby-value">3</span>]]
206:       
207:       <span class="ruby-identifier">signature</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKCS7</span>.<span class="ruby-identifier">sign</span>(<span class="ruby-identifier">certificate</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">signable_data</span>, [], <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKCS7</span><span class="ruby-operator">::</span><span class="ruby-constant">DETACHED</span> <span class="ruby-operator">|</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKCS7</span><span class="ruby-operator">::</span><span class="ruby-constant">BINARY</span>).<span class="ruby-identifier">to_der</span>
208:       <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">Contents</span>[<span class="ruby-value">0</span>, <span class="ruby-identifier">signature</span>.<span class="ruby-identifier">size</span>] = <span class="ruby-identifier">signature</span>
209:       
210:       <span class="ruby-comment cmt">#</span>
211:       <span class="ruby-comment cmt"># No more modification are allowed after signing.</span>
212:       <span class="ruby-comment cmt">#</span>
213:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">freeze</span>
214:       
215:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000481" class="method-detail">
        <a name="M000481"></a>

        <div class="method-heading">
          <a href="#M000481" class="method-signature">
          <span class="method-name">encrypt</span><span class="method-args">(userpasswd, ownerpasswd, options = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Encrypts the current document with the provided passwords. The document
will be encrypted at writing-on-disk time.
</p>
<table>
<tr><td valign="top"><em>userpasswd</em>:</td><td>The user password.

</td></tr>
<tr><td valign="top"><em>ownerpasswd</em>:</td><td>The owner password.

</td></tr>
<tr><td valign="top"><em>options</em>:</td><td>A set of options to configure encryption.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000481-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000481-source">
<pre>
     <span class="ruby-comment cmt"># File origami/encryption.rb, line 183</span>
183:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">encrypt</span>(<span class="ruby-identifier">userpasswd</span>, <span class="ruby-identifier">ownerpasswd</span>, <span class="ruby-identifier">options</span> = {})
184:     
185:       <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">is_encrypted?</span>
186:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">EncryptionError</span>, <span class="ruby-value str">&quot;PDF is already encrypted&quot;</span>
187:       <span class="ruby-keyword kw">end</span>
188: 
189:       <span class="ruby-comment cmt">#</span>
190:       <span class="ruby-comment cmt"># Default encryption options.</span>
191:       <span class="ruby-comment cmt">#</span>
192:       <span class="ruby-identifier">params</span> = 
193:       {
194:         <span class="ruby-identifier">:Algorithm</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">:RC4</span>,         <span class="ruby-comment cmt"># :RC4 or :AES</span>
195:         <span class="ruby-identifier">:KeyLength</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">128</span>,          <span class="ruby-comment cmt"># Key size in bits</span>
196:         <span class="ruby-identifier">:EncryptMetadata</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">true</span>,    <span class="ruby-comment cmt"># Metadata shall be encrypted?</span>
197:         <span class="ruby-identifier">:Permissions</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Encryption</span><span class="ruby-operator">::</span><span class="ruby-constant">Standard</span><span class="ruby-operator">::</span><span class="ruby-constant">Permissions</span><span class="ruby-operator">::</span><span class="ruby-constant">ALL</span>    <span class="ruby-comment cmt"># Document permissions</span>
198:       }
199: 
200:       <span class="ruby-identifier">params</span>.<span class="ruby-identifier">update</span>(<span class="ruby-identifier">options</span>)
201: 
202:       <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:Algorithm</span>]
203:       <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:RC4</span>
204:         <span class="ruby-identifier">algorithm</span> = <span class="ruby-constant">Encryption</span><span class="ruby-operator">::</span><span class="ruby-constant">ARC4</span>
205:         <span class="ruby-keyword kw">if</span> (<span class="ruby-value">40</span><span class="ruby-operator">..</span><span class="ruby-value">128</span>) <span class="ruby-operator">===</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:KeyLength</span>] <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:KeyLength</span>] <span class="ruby-operator">%</span> <span class="ruby-value">8</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
206:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:KeyLength</span>] <span class="ruby-operator">&gt;</span> <span class="ruby-value">40</span>
207:             <span class="ruby-identifier">version</span> = <span class="ruby-value">2</span>
208:             <span class="ruby-identifier">revision</span> = <span class="ruby-value">3</span>
209:           <span class="ruby-keyword kw">else</span>
210:             <span class="ruby-identifier">version</span> = <span class="ruby-value">1</span>
211:             <span class="ruby-identifier">revision</span> = <span class="ruby-value">2</span>
212:           <span class="ruby-keyword kw">end</span>
213:         <span class="ruby-keyword kw">else</span>
214:           <span class="ruby-identifier">raise</span> <span class="ruby-constant">EncryptionError</span>, <span class="ruby-value str">&quot;Invalid key length&quot;</span>
215:         <span class="ruby-keyword kw">end</span>
216:       <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:AES</span>
217:         <span class="ruby-identifier">algorithm</span> = <span class="ruby-constant">Encryption</span><span class="ruby-operator">::</span><span class="ruby-constant">AES</span>
218:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:KeyLength</span>] <span class="ruby-operator">==</span> <span class="ruby-value">128</span> 
219:           <span class="ruby-identifier">version</span> = <span class="ruby-identifier">revision</span> = <span class="ruby-value">4</span>
220:         <span class="ruby-keyword kw">else</span>
221:           <span class="ruby-identifier">raise</span> <span class="ruby-constant">EncryptionError</span>, <span class="ruby-value str">&quot;Invalid key length&quot;</span>
222:         <span class="ruby-keyword kw">end</span>
223:       <span class="ruby-keyword kw">else</span>
224:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">EncryptionNotSupportedError</span>, <span class="ruby-node">&quot;Algorithm not supported : #{params[:Algorithm]}&quot;</span>
225:       <span class="ruby-keyword kw">end</span>
226:      
227:       <span class="ruby-identifier">id</span> = (<span class="ruby-identifier">get_doc_attr</span>(<span class="ruby-identifier">:ID</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">gen_id</span>).<span class="ruby-identifier">first</span>
228: 
229:       <span class="ruby-identifier">handler</span> = <span class="ruby-constant">Encryption</span><span class="ruby-operator">::</span><span class="ruby-constant">Standard</span><span class="ruby-operator">::</span><span class="ruby-constant">Dictionary</span>.<span class="ruby-identifier">new</span>
230:       <span class="ruby-identifier">handler</span>.<span class="ruby-constant">Filter</span> = <span class="ruby-identifier">:Standard</span> <span class="ruby-comment cmt">#:nodoc:</span>
231:       <span class="ruby-identifier">handler</span>.<span class="ruby-constant">V</span> = <span class="ruby-identifier">version</span>
232:       <span class="ruby-identifier">handler</span>.<span class="ruby-constant">R</span> = <span class="ruby-identifier">revision</span>
233:       <span class="ruby-identifier">handler</span>.<span class="ruby-constant">Length</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:KeyLength</span>]
234:       <span class="ruby-identifier">handler</span>.<span class="ruby-constant">P</span> = <span class="ruby-value">-1</span> <span class="ruby-comment cmt"># params[:Permissions] </span>
235:       
236:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">revision</span> <span class="ruby-operator">==</span> <span class="ruby-value">4</span>
237:         <span class="ruby-identifier">handler</span>.<span class="ruby-constant">EncryptMetadata</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:EncryptMetadata</span>]
238:         <span class="ruby-identifier">handler</span>.<span class="ruby-constant">CF</span> = <span class="ruby-constant">Dictionary</span>.<span class="ruby-identifier">new</span>
239:         <span class="ruby-identifier">cryptfilter</span> = <span class="ruby-constant">Encryption</span><span class="ruby-operator">::</span><span class="ruby-constant">CryptFilterDictionary</span>.<span class="ruby-identifier">new</span>
240:         <span class="ruby-identifier">cryptfilter</span>.<span class="ruby-constant">AuthEvent</span> = <span class="ruby-identifier">:DocOpen</span>
241:         <span class="ruby-identifier">cryptfilter</span>.<span class="ruby-constant">CFM</span> = <span class="ruby-identifier">:AESV2</span>
242:         <span class="ruby-identifier">cryptfilter</span>.<span class="ruby-constant">Length</span> = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:KeyLength</span>] <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">3</span>
243: 
244:         <span class="ruby-identifier">handler</span>.<span class="ruby-constant">CF</span>[<span class="ruby-identifier">:StdCF</span>] = <span class="ruby-identifier">cryptfilter</span>
245:         <span class="ruby-identifier">handler</span>.<span class="ruby-constant">StmF</span> = <span class="ruby-identifier">handler</span>.<span class="ruby-constant">StrF</span> = <span class="ruby-identifier">:StdCF</span>
246:       <span class="ruby-keyword kw">end</span>
247:       
248:       <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">set_owner_password</span>(<span class="ruby-identifier">userpasswd</span>, <span class="ruby-identifier">ownerpasswd</span>)
249:       <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">set_user_password</span>(<span class="ruby-identifier">userpasswd</span>, <span class="ruby-identifier">id</span>)
250:       
251:       <span class="ruby-identifier">encryption_key</span> = <span class="ruby-identifier">handler</span>.<span class="ruby-identifier">compute_encryption_key</span>(<span class="ruby-identifier">userpasswd</span>, <span class="ruby-identifier">id</span>)
252: 
253:       <span class="ruby-identifier">fileInfo</span> = <span class="ruby-identifier">get_trailer_info</span>
254:       <span class="ruby-identifier">fileInfo</span>[<span class="ruby-identifier">:Encrypt</span>] = <span class="ruby-keyword kw">self</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">handler</span>
255: 
256:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">extend</span>(<span class="ruby-constant">Encryption</span><span class="ruby-operator">::</span><span class="ruby-constant">EncryptedDocument</span>)
257:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">encryption_dict</span> = <span class="ruby-identifier">handler</span>
258:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">encryption_key</span> = <span class="ruby-identifier">encryption_key</span>
259:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">stm_algo</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">str_algo</span> = <span class="ruby-identifier">algorithm</span>
260: 
261:       <span class="ruby-keyword kw">self</span>
262:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000523" class="method-detail">
        <a name="M000523"></a>

        <div class="method-heading">
          <a href="#M000523" class="method-signature">
          <span class="method-name">export_to_graph</span><span class="method-args">(filename)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Exports the document to a dot Graphiz file.
</p>
<table>
<tr><td valign="top"><em>filename</em>:</td><td>The path where to <a href="PDF.html#M000492">save</a> the file.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000523-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000523-source">
<pre>
     <span class="ruby-comment cmt"># File origami/export.rb, line 34</span>
 34:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">export_to_graph</span>(<span class="ruby-identifier">filename</span>)
 35:       
 36:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">appearance</span>(<span class="ruby-identifier">object</span>) <span class="ruby-comment cmt">#:nodoc:</span>
 37:       
 38:         <span class="ruby-identifier">label</span> = <span class="ruby-identifier">object</span>.<span class="ruby-identifier">type</span>.<span class="ruby-identifier">to_s</span>
 39:         <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">object</span>
 40:           <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Catalog</span>
 41:             <span class="ruby-identifier">fontcolor</span> = <span class="ruby-value str">&quot;red&quot;</span>
 42:             <span class="ruby-identifier">color</span> = <span class="ruby-value str">&quot;mistyrose&quot;</span>
 43:             <span class="ruby-identifier">shape</span> = <span class="ruby-value str">&quot;doublecircle&quot;</span>
 44:           <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Name</span>, <span class="ruby-constant">Number</span>
 45:             <span class="ruby-identifier">label</span> = <span class="ruby-identifier">object</span>.<span class="ruby-identifier">value</span> 
 46:             <span class="ruby-identifier">fontcolor</span> = <span class="ruby-value str">&quot;orange&quot;</span>
 47:             <span class="ruby-identifier">color</span> = <span class="ruby-value str">&quot;lightgoldenrodyellow&quot;</span>
 48:             <span class="ruby-identifier">shape</span> = <span class="ruby-value str">&quot;polygon&quot;</span>
 49:            <span class="ruby-keyword kw">when</span> <span class="ruby-constant">String</span>
 50:             <span class="ruby-identifier">label</span> = <span class="ruby-identifier">object</span>.<span class="ruby-identifier">value</span> <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">object</span>.<span class="ruby-identifier">is_binary_data?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">object</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">50</span>)
 51:             <span class="ruby-identifier">fontcolor</span> = <span class="ruby-value str">&quot;red&quot;</span>
 52:             <span class="ruby-identifier">color</span> = <span class="ruby-value str">&quot;white&quot;</span>
 53:             <span class="ruby-identifier">shape</span> = <span class="ruby-value str">&quot;polygon&quot;</span>
 54:           <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Array</span>
 55:             <span class="ruby-identifier">fontcolor</span> = <span class="ruby-value str">&quot;green&quot;</span>
 56:             <span class="ruby-identifier">color</span> = <span class="ruby-value str">&quot;lightcyan&quot;</span>
 57:             <span class="ruby-identifier">shape</span> = <span class="ruby-value str">&quot;ellipse&quot;</span>
 58:         <span class="ruby-keyword kw">else</span>
 59:           <span class="ruby-identifier">fontcolor</span> = <span class="ruby-value str">&quot;blue&quot;</span>
 60:           <span class="ruby-identifier">color</span> = <span class="ruby-value str">&quot;aliceblue&quot;</span>
 61:           <span class="ruby-identifier">shape</span> = <span class="ruby-value str">&quot;ellipse&quot;</span>
 62:         <span class="ruby-keyword kw">end</span>
 63:       
 64:         { <span class="ruby-identifier">:label</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">label</span>, <span class="ruby-identifier">:fontcolor</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">fontcolor</span>, <span class="ruby-identifier">:color</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">color</span>, <span class="ruby-identifier">:shape</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">shape</span> }
 65:       <span class="ruby-keyword kw">end</span>
 66:       
 67:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add_edges</span>(<span class="ruby-identifier">pdf</span>, <span class="ruby-identifier">fd</span>, <span class="ruby-identifier">object</span>) <span class="ruby-comment cmt">#:nodoc:</span>
 68:         
 69:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">object</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>) <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">object</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">ObjectStream</span>)
 70:           
 71:           <span class="ruby-identifier">object</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">subobj</span><span class="ruby-operator">|</span>
 72:             <span class="ruby-identifier">subobj</span> = <span class="ruby-identifier">subobj</span>.<span class="ruby-identifier">solve</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">subobj</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Reference</span>) 
 73:             <span class="ruby-identifier">fd</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;\t#{object.object_id} -&gt; #{subobj.object_id}\n&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">subobj</span>.<span class="ruby-identifier">nil?</span>
 74:           }
 75:           
 76:         <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">object</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Dictionary</span>)
 77:           
 78:           <span class="ruby-identifier">object</span>.<span class="ruby-identifier">each_pair</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">name</span>, <span class="ruby-identifier">subobj</span><span class="ruby-operator">|</span>
 79:             <span class="ruby-identifier">subobj</span> = <span class="ruby-identifier">subobj</span>.<span class="ruby-identifier">solve</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">subobj</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Reference</span>) 
 80:             <span class="ruby-identifier">fd</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;\t#{object.object_id} -&gt; #{subobj.object_id} [label=\&quot;#{name.value}\&quot;,fontsize=7];\n&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">subobj</span>.<span class="ruby-identifier">nil?</span>
 81:           }
 82:           
 83:         <span class="ruby-keyword kw">end</span>
 84:         
 85:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">object</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Stream</span>)
 86:           
 87:           <span class="ruby-identifier">object</span>.<span class="ruby-identifier">dictionary</span>.<span class="ruby-identifier">each_pair</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
 88:             <span class="ruby-identifier">value</span> = <span class="ruby-identifier">value</span>.<span class="ruby-identifier">solve</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Reference</span>)
 89:             <span class="ruby-identifier">fd</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;\t#{object.object_id} -&gt; #{value.object_id} [label=\&quot;#{key.value}\&quot;,fontsize=7];\n&quot;</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">nil?</span>
 90:           }
 91:           
 92:         <span class="ruby-keyword kw">end</span>
 93:         
 94:       <span class="ruby-keyword kw">end</span>
 95:       
 96:       <span class="ruby-identifier">graphname</span> = <span class="ruby-value str">&quot;PDF&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">graphname</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">graphname</span>.<span class="ruby-identifier">empty?</span>
 97:       <span class="ruby-identifier">fd</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">filename</span>, <span class="ruby-value str">&quot;w&quot;</span>)
 98:     
 99:       <span class="ruby-keyword kw">begin</span>
100:         <span class="ruby-identifier">fd</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;digraph #{graphname} {\n\n&quot;</span>
101:         
102:         <span class="ruby-identifier">objects</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">objects</span>(<span class="ruby-identifier">:include_keys</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">false</span>).<span class="ruby-identifier">find_all</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">obj</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Reference</span>) }
103:         
104:         <span class="ruby-identifier">objects</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">object</span><span class="ruby-operator">|</span>
105:           <span class="ruby-identifier">attr</span> = <span class="ruby-identifier">appearance</span>(<span class="ruby-identifier">object</span>)
106:           
107:           <span class="ruby-identifier">fd</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;\t#{object.object_id} [label=\&quot;#{attr[:label]}\&quot;,shape=#{attr[:shape]},color=#{attr[:color]},style=filled,fontcolor=#{attr[:fontcolor]}];\n&quot;</span>
108:           
109:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">object</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Stream</span>)
110:             
111:             <span class="ruby-identifier">object</span>.<span class="ruby-identifier">dictionary</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
112:               <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Reference</span>)
113:                 <span class="ruby-identifier">attr</span> = <span class="ruby-identifier">appearance</span>(<span class="ruby-identifier">value</span>)
114:                 <span class="ruby-identifier">fd</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;\t#{value.object_id} [label=\&quot;#{attr[:label]}\&quot;,shape=#{attr[:shape]},color=#{attr[:color]},style=filled,fontcolor=#{attr[:fontcolor]}];\n&quot;</span>
115:               <span class="ruby-keyword kw">end</span>
116:             }
117:             
118:           <span class="ruby-keyword kw">end</span>
119:           
120:           <span class="ruby-identifier">add_edges</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">fd</span>, <span class="ruby-identifier">object</span>)
121:         }
122:         <span class="ruby-identifier">fd</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\n}&quot;</span>
123:       <span class="ruby-keyword kw">ensure</span>
124:         <span class="ruby-identifier">fd</span>.<span class="ruby-identifier">close</span>
125:       <span class="ruby-keyword kw">end</span>
126:       
127:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000524" class="method-detail">
        <a name="M000524"></a>

        <div class="method-heading">
          <a href="#M000524" class="method-signature">
          <span class="method-name">export_to_graphml</span><span class="method-args">(filename)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Exports the document to a GraphML file.
</p>
<table>
<tr><td valign="top"><em>filename</em>:</td><td>The path where to <a href="PDF.html#M000492">save</a> the file.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000524-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000524-source">
<pre>
     <span class="ruby-comment cmt"># File origami/export.rb, line 133</span>
133:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">export_to_graphml</span>(<span class="ruby-identifier">filename</span>)
134:       
135:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">declare_node</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">attr</span>) <span class="ruby-comment cmt">#:nodoc:</span>
136:         <span class="ruby-node">&quot; &lt;node id=\&quot;#{id}\&quot;&gt;\n&quot;</span> <span class="ruby-operator">&lt;&lt;</span>
137:         <span class="ruby-value str">&quot;  &lt;data key=\&quot;d0\&quot;&gt;\n&quot;</span> <span class="ruby-operator">&lt;&lt;</span>
138:         <span class="ruby-value str">&quot;    &lt;y:ShapeNode&gt;\n&quot;</span> <span class="ruby-operator">&lt;&lt;</span>
139:         <span class="ruby-node">&quot;     &lt;y:NodeLabel&gt;#{attr[:label]}&lt;/y:NodeLabel&gt;\n&quot;</span> <span class="ruby-operator">&lt;&lt;</span>
140:         <span class="ruby-comment cmt">#~ &quot;     &lt;y:Shape type=\&quot;#{attr[:shape]}\&quot;/&gt;\n&quot; &lt;&lt;</span>
141:         <span class="ruby-value str">&quot;    &lt;/y:ShapeNode&gt;\n&quot;</span> <span class="ruby-operator">&lt;&lt;</span>
142:         <span class="ruby-value str">&quot;  &lt;/data&gt;\n&quot;</span> <span class="ruby-operator">&lt;&lt;</span>
143:         <span class="ruby-value str">&quot; &lt;/node&gt;\n&quot;</span>
144:       <span class="ruby-keyword kw">end</span>
145:       
146:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">declare_edge</span>(<span class="ruby-identifier">id</span>, <span class="ruby-identifier">src</span>, <span class="ruby-identifier">dest</span>, <span class="ruby-identifier">label</span> = <span class="ruby-keyword kw">nil</span>) <span class="ruby-comment cmt">#:nodoc:</span>
147:         <span class="ruby-node">&quot; &lt;edge id=\&quot;#{id}\&quot; source=\&quot;#{src}\&quot; target=\&quot;#{dest}\&quot;&gt;\n&quot;</span> <span class="ruby-operator">&lt;&lt;</span> 
148:         <span class="ruby-value str">&quot;  &lt;data key=\&quot;d1\&quot;&gt;\n&quot;</span> <span class="ruby-operator">&lt;&lt;</span>
149:         <span class="ruby-value str">&quot;   &lt;y:PolyLineEdge&gt;\n&quot;</span> <span class="ruby-operator">&lt;&lt;</span>
150:         <span class="ruby-value str">&quot;    &lt;y:LineStyle type=\&quot;line\&quot; width=\&quot;1.0\&quot; color=\&quot;#000000\&quot;/&gt;\n&quot;</span> <span class="ruby-operator">&lt;&lt;</span>
151:         <span class="ruby-value str">&quot;    &lt;y:Arrows source=\&quot;none\&quot; target=\&quot;standard\&quot;/&gt;\n&quot;</span> <span class="ruby-operator">&lt;&lt;</span> 
152:         <span class="ruby-node">&quot;    &lt;y:EdgeLabel&gt;#{label.to_s}&lt;/y:EdgeLabel&gt;\n&quot;</span> <span class="ruby-operator">&lt;&lt;</span>
153:         <span class="ruby-value str">&quot;   &lt;/y:PolyLineEdge&gt;\n&quot;</span> <span class="ruby-operator">&lt;&lt;</span>
154:         <span class="ruby-value str">&quot;  &lt;/data&gt;\n&quot;</span> <span class="ruby-operator">&lt;&lt;</span>
155:         <span class="ruby-value str">&quot; &lt;/edge&gt;\n&quot;</span>
156:       <span class="ruby-keyword kw">end</span>
157:       
158:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">appearance</span>(<span class="ruby-identifier">object</span>) <span class="ruby-comment cmt">#:nodoc:</span>
159:       
160:         <span class="ruby-identifier">label</span> = <span class="ruby-identifier">object</span>.<span class="ruby-identifier">type</span>.<span class="ruby-identifier">to_s</span>
161:         <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">object</span>
162:           <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Catalog</span>
163:             <span class="ruby-identifier">fontcolor</span> = <span class="ruby-value str">&quot;red&quot;</span>
164:             <span class="ruby-identifier">color</span> = <span class="ruby-value str">&quot;mistyrose&quot;</span>
165:             <span class="ruby-identifier">shape</span> = <span class="ruby-value str">&quot;doublecircle&quot;</span>
166:           <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Name</span>, <span class="ruby-constant">Number</span>
167:             <span class="ruby-identifier">label</span> = <span class="ruby-identifier">object</span>.<span class="ruby-identifier">value</span> 
168:             <span class="ruby-identifier">fontcolor</span> = <span class="ruby-value str">&quot;orange&quot;</span>
169:             <span class="ruby-identifier">color</span> = <span class="ruby-value str">&quot;lightgoldenrodyellow&quot;</span>
170:             <span class="ruby-identifier">shape</span> = <span class="ruby-value str">&quot;polygon&quot;</span>
171:           <span class="ruby-keyword kw">when</span> <span class="ruby-constant">String</span>
172:             <span class="ruby-identifier">label</span> = <span class="ruby-identifier">object</span>.<span class="ruby-identifier">value</span> <span class="ruby-keyword kw">unless</span> (<span class="ruby-identifier">object</span>.<span class="ruby-identifier">is_binary_data?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">object</span>.<span class="ruby-identifier">length</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">50</span>)
173:             <span class="ruby-identifier">fontcolor</span> = <span class="ruby-value str">&quot;red&quot;</span>
174:             <span class="ruby-identifier">color</span> = <span class="ruby-value str">&quot;white&quot;</span>
175:             <span class="ruby-identifier">shape</span> = <span class="ruby-value str">&quot;polygon&quot;</span>
176:           <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Array</span>
177:             <span class="ruby-identifier">fontcolor</span> = <span class="ruby-value str">&quot;green&quot;</span>
178:             <span class="ruby-identifier">color</span> = <span class="ruby-value str">&quot;lightcyan&quot;</span>
179:             <span class="ruby-identifier">shape</span> = <span class="ruby-value str">&quot;ellipse&quot;</span>
180:         <span class="ruby-keyword kw">else</span>
181:           <span class="ruby-identifier">fontcolor</span> = <span class="ruby-value str">&quot;blue&quot;</span>
182:           <span class="ruby-identifier">color</span> = <span class="ruby-value str">&quot;aliceblue&quot;</span>
183:           <span class="ruby-identifier">shape</span> = <span class="ruby-value str">&quot;ellipse&quot;</span>
184:         <span class="ruby-keyword kw">end</span>
185:       
186:         { <span class="ruby-identifier">:label</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">label</span>, <span class="ruby-identifier">:fontcolor</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">fontcolor</span>, <span class="ruby-identifier">:color</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">color</span>, <span class="ruby-identifier">:shape</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">shape</span> }
187:       <span class="ruby-keyword kw">end</span>
188:       
189:      <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add_edges</span>(<span class="ruby-identifier">pdf</span>, <span class="ruby-identifier">fd</span>, <span class="ruby-identifier">object</span>, <span class="ruby-identifier">id</span>) <span class="ruby-comment cmt">#:nodoc:</span>
190:         
191:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">object</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>) <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">object</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">ObjectStream</span>)
192:           
193:           <span class="ruby-identifier">object</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">subobj</span><span class="ruby-operator">|</span>
194:             
195:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">subobj</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Reference</span>) <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">subobj</span> = <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">indirect_objects</span>[<span class="ruby-identifier">subobj</span>] <span class="ruby-keyword kw">end</span>
196:             
197:             <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">subobj</span>.<span class="ruby-identifier">nil?</span>
198:               <span class="ruby-identifier">fd</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">declare_edge</span>(<span class="ruby-node">&quot;e#{id}&quot;</span>, <span class="ruby-node">&quot;n#{object.object_id}&quot;</span>, <span class="ruby-node">&quot;n#{subobj.object_id}&quot;</span>)
199:               <span class="ruby-identifier">id</span> = <span class="ruby-identifier">id</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
200:             <span class="ruby-keyword kw">end</span>
201:           }
202:           
203:         <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">object</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Dictionary</span>)
204:           
205:           <span class="ruby-identifier">object</span>.<span class="ruby-identifier">each_pair</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">name</span>, <span class="ruby-identifier">subobj</span><span class="ruby-operator">|</span>
206:             
207:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">subobj</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Reference</span>) <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">subobj</span> = <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">indirect_objects</span>[<span class="ruby-identifier">subobj</span>] <span class="ruby-keyword kw">end</span>
208:             
209:             <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">subobj</span>.<span class="ruby-identifier">nil?</span>
210:               <span class="ruby-identifier">fd</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">declare_edge</span>(<span class="ruby-node">&quot;e#{id}&quot;</span>, <span class="ruby-node">&quot;n#{object.object_id}&quot;</span>, <span class="ruby-node">&quot;n#{subobj.object_id}&quot;</span>, <span class="ruby-identifier">name</span>.<span class="ruby-identifier">value</span>)
211:               <span class="ruby-identifier">id</span> = <span class="ruby-identifier">id</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
212:             <span class="ruby-keyword kw">end</span>
213:           }
214:           
215:         <span class="ruby-keyword kw">end</span>
216:         
217:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">object</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Stream</span>)
218:           
219:           <span class="ruby-identifier">object</span>.<span class="ruby-identifier">dictionary</span>.<span class="ruby-identifier">each_pair</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
220:           
221:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Reference</span>) <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">value</span> = <span class="ruby-identifier">pdf</span>.<span class="ruby-identifier">indirect_objects</span>[<span class="ruby-identifier">subobj</span>] <span class="ruby-keyword kw">end</span>
222:             
223:             <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">nil?</span>
224:               <span class="ruby-identifier">fd</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">declare_edge</span>(<span class="ruby-node">&quot;e#{id}&quot;</span>, <span class="ruby-node">&quot;n#{object.object_id}&quot;</span>, <span class="ruby-node">&quot;n#{value.object_id}&quot;</span>, <span class="ruby-identifier">key</span>.<span class="ruby-identifier">value</span>)
225:               <span class="ruby-identifier">id</span> = <span class="ruby-identifier">id</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
226:             <span class="ruby-keyword kw">end</span>
227:           }
228:           
229:         <span class="ruby-keyword kw">end</span>
230:         
231:         <span class="ruby-identifier">id</span>
232:       <span class="ruby-keyword kw">end</span>
233:       
234:       <span class="ruby-ivar">@@edge_nb</span> = <span class="ruby-value">1</span>
235:       
236:       <span class="ruby-identifier">graphname</span> = <span class="ruby-value str">&quot;PDF&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">graphname</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">graphname</span>.<span class="ruby-identifier">empty?</span>
237:       
238:       <span class="ruby-identifier">fd</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">filename</span>, <span class="ruby-value str">&quot;w&quot;</span>)
239:       
240:       <span class="ruby-identifier">edge_nb</span> = <span class="ruby-value">1</span>
241:       <span class="ruby-keyword kw">begin</span>
242:         
243:         <span class="ruby-identifier">fd</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">'&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;'</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\n&quot;</span>
244:         <span class="ruby-identifier">fd</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">'&lt;graphml xmlns=&quot;http://graphml.graphdrawing.org/xmlns/graphml&quot;'</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\n&quot;</span>
245:         <span class="ruby-identifier">fd</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">' xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;'</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\n&quot;</span>
246:         <span class="ruby-identifier">fd</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">' xsi:schemaLocation=&quot;http://graphml.graphdrawing.org/xmlns/graphml '</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\n&quot;</span>
247:         <span class="ruby-identifier">fd</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">' http://www.yworks.com/xml/schema/graphml/1.0/ygraphml.xsd&quot;'</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\n&quot;</span>
248:         <span class="ruby-identifier">fd</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">' xmlns:y=&quot;http://www.yworks.com/xml/graphml&quot;&gt;'</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\n&quot;</span>
249:         <span class="ruby-identifier">fd</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">'&lt;key id=&quot;d0&quot; for=&quot;node&quot; yfiles.type=&quot;nodegraphics&quot;/&gt;'</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\n&quot;</span>
250:         <span class="ruby-identifier">fd</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">'&lt;key id=&quot;d1&quot; for=&quot;edge&quot; yfiles.type=&quot;edgegraphics&quot;/&gt;'</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\n&quot;</span>
251:         <span class="ruby-identifier">fd</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;&lt;graph id=\&quot;#{graphname}\&quot; edgedefault=\&quot;directed\&quot;&gt;\n&quot;</span>
252:         
253:         <span class="ruby-identifier">objects</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">objects</span>(<span class="ruby-keyword kw">true</span>).<span class="ruby-identifier">find_all</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">obj</span><span class="ruby-operator">|</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Reference</span>) }
254:         
255:         <span class="ruby-identifier">objects</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">object</span><span class="ruby-operator">|</span>
256:           
257:           <span class="ruby-identifier">fd</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">declare_node</span>(<span class="ruby-node">&quot;n#{object.object_id}&quot;</span>, <span class="ruby-identifier">appearance</span>(<span class="ruby-identifier">object</span>))
258:           
259:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">object</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Stream</span>)
260:             
261:             <span class="ruby-identifier">object</span>.<span class="ruby-identifier">dictionary</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
262:             
263:               <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Reference</span>)
264:                 <span class="ruby-identifier">fd</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">declare_node</span>(<span class="ruby-identifier">value</span>.<span class="ruby-identifier">object_id</span>, <span class="ruby-identifier">appearance</span>(<span class="ruby-identifier">value</span>))
265:               <span class="ruby-keyword kw">end</span>
266:             }
267:           <span class="ruby-keyword kw">end</span>
268:           
269:           <span class="ruby-identifier">edge_nb</span> = <span class="ruby-identifier">add_edges</span>(<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">fd</span>, <span class="ruby-identifier">object</span>, <span class="ruby-identifier">edge_nb</span>)
270:         }
271:         
272:         <span class="ruby-identifier">fd</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">'&lt;/graph&gt;'</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\n&quot;</span>
273:         <span class="ruby-identifier">fd</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">'&lt;/graphml&gt;'</span>
274:         
275:       <span class="ruby-keyword kw">ensure</span>
276:         <span class="ruby-identifier">fd</span>.<span class="ruby-identifier">close</span>
277:       <span class="ruby-keyword kw">end</span>
278:       
279:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000491" class="method-detail">
        <a name="M000491"></a>

        <div class="method-heading">
          <a href="#M000491" class="method-signature">
          <span class="method-name">filesize</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the virtual file size as it would be taking on disk.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000491-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000491-source">
<pre>
     <span class="ruby-comment cmt"># File origami/pdf.rb, line 211</span>
211:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">filesize</span>
212:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_bin</span>(<span class="ruby-identifier">:rebuildxrefs</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">false</span>).<span class="ruby-identifier">size</span>
213:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000498" class="method-detail">
        <a name="M000498"></a>

        <div class="method-heading">
          <a href="#M000498" class="method-signature">
          <span class="method-name">find</span><span class="method-args">(params = {}, &amp;b)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an array of <a href="PDF.html#M000499">objects</a> matching
specified block.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000498-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000498-source">
<pre>
     <span class="ruby-comment cmt"># File origami/pdf.rb, line 349</span>
349:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">find</span>(<span class="ruby-identifier">params</span> = {}, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">b</span>)
350:       
351:       <span class="ruby-identifier">options</span> =
352:       {
353:         <span class="ruby-identifier">:only_indirect</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">false</span>
354:       }
355:       <span class="ruby-identifier">options</span>.<span class="ruby-identifier">update</span>(<span class="ruby-identifier">params</span>)
356:       
357:       <span class="ruby-identifier">objset</span> = (<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:only_indirect</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span>) <span class="ruby-operator">?</span> 
358:         <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">indirect_objects</span>.<span class="ruby-identifier">values</span> <span class="ruby-operator">:</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">objects</span>
359: 
360:       <span class="ruby-identifier">objset</span>.<span class="ruby-identifier">find_all</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">b</span>)
361:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000485" class="method-detail">
        <a name="M000485"></a>

        <div class="method-heading">
          <a href="#M000485" class="method-signature">
          <span class="method-name">get_document_info</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the document information dictionary if present.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000485-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000485-source">
<pre>
    <span class="ruby-comment cmt"># File origami/metadata.rb, line 49</span>
49:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_document_info</span>
50:       <span class="ruby-identifier">get_doc_attr</span> <span class="ruby-identifier">:Info</span>
51:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000486" class="method-detail">
        <a name="M000486"></a>

        <div class="method-heading">
          <a href="#M000486" class="method-signature">
          <span class="method-name">get_metadata</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns a Hash of the information found in the metadata stream
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000486-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000486-source">
<pre>
    <span class="ruby-comment cmt"># File origami/metadata.rb, line 56</span>
56:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_metadata</span>
57:       <span class="ruby-identifier">metadata_stm</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-constant">Metadata</span>
58: 
59:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">metadata_stm</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Stream</span>)
60:         <span class="ruby-identifier">doc</span> = <span class="ruby-constant">REXML</span><span class="ruby-operator">::</span><span class="ruby-constant">Document</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">metadata_stm</span>.<span class="ruby-identifier">data</span>)
61: 
62:         <span class="ruby-identifier">info</span> = {}
63: 
64:         <span class="ruby-identifier">doc</span>.<span class="ruby-identifier">elements</span>.<span class="ruby-identifier">each</span>(<span class="ruby-value str">'*/*/rdf:Description'</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">description</span><span class="ruby-operator">|</span>
65:           
66:           <span class="ruby-identifier">description</span>.<span class="ruby-identifier">attributes</span>.<span class="ruby-identifier">each_attribute</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">attr</span><span class="ruby-operator">|</span>
67:             <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">attr</span>.<span class="ruby-identifier">prefix</span>
68:               <span class="ruby-keyword kw">when</span> <span class="ruby-value str">'pdf'</span>,<span class="ruby-value str">'xap'</span>,<span class="ruby-value str">'pdf'</span>
69:                 <span class="ruby-identifier">info</span>[<span class="ruby-identifier">attr</span>.<span class="ruby-identifier">name</span>] = <span class="ruby-identifier">attr</span>.<span class="ruby-identifier">value</span>
70:             <span class="ruby-keyword kw">end</span>
71:           <span class="ruby-keyword kw">end</span>
72: 
73:           <span class="ruby-identifier">description</span>.<span class="ruby-identifier">elements</span>.<span class="ruby-identifier">each</span>(<span class="ruby-value str">'*'</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">element</span><span class="ruby-operator">|</span>
74:             <span class="ruby-identifier">value</span> = (<span class="ruby-identifier">element</span>.<span class="ruby-identifier">elements</span>[<span class="ruby-value str">'.//rdf:li'</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">element</span>).<span class="ruby-identifier">text</span>
75:             <span class="ruby-identifier">info</span>[<span class="ruby-identifier">element</span>.<span class="ruby-identifier">name</span>] = <span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_s</span>
76:           <span class="ruby-keyword kw">end</span>
77: 
78:         <span class="ruby-keyword kw">end</span>
79: 
80:         <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">info</span>
81:       <span class="ruby-keyword kw">end</span>
82:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000495" class="method-detail">
        <a name="M000495"></a>

        <div class="method-heading">
          <a href="#M000495" class="method-signature">
          <span class="method-name">grep</span><span class="method-args">(*patterns)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an array of Objects whose content is matching <em>pattern</em>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000495-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000495-source">
<pre>
     <span class="ruby-comment cmt"># File origami/pdf.rb, line 272</span>
272:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">grep</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">patterns</span>)
273: 
274:       <span class="ruby-identifier">patterns</span>.<span class="ruby-identifier">map!</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">pattern</span><span class="ruby-operator">|</span>
275:         <span class="ruby-identifier">pattern</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-operator">::</span><span class="ruby-constant">String</span>) <span class="ruby-operator">?</span> <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">escape</span>(<span class="ruby-identifier">pattern</span>)) <span class="ruby-operator">:</span> <span class="ruby-identifier">pattern</span>
276:       <span class="ruby-keyword kw">end</span>
277: 
278:       <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">patterns</span>.<span class="ruby-identifier">all?</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">pattern</span><span class="ruby-operator">|</span> <span class="ruby-identifier">pattern</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Regexp</span>) }
279:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-value str">&quot;Expected a String or Regexp&quot;</span>
280:       <span class="ruby-keyword kw">end</span>
281: 
282:       <span class="ruby-identifier">result</span> = []
283:       <span class="ruby-identifier">objects</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">obj</span><span class="ruby-operator">|</span>
284:         <span class="ruby-keyword kw">begin</span>
285:           <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">obj</span>
286:             <span class="ruby-keyword kw">when</span> <span class="ruby-constant">String</span>, <span class="ruby-constant">Name</span>
287:               <span class="ruby-identifier">result</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">obj</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">patterns</span>.<span class="ruby-identifier">any?</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">pattern</span><span class="ruby-operator">|</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">pattern</span>)}
288:             <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Stream</span>
289:               <span class="ruby-identifier">result</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">obj</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">patterns</span>.<span class="ruby-identifier">any?</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">pattern</span><span class="ruby-operator">|</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">data</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">pattern</span>)}
290:           <span class="ruby-keyword kw">end</span>
291:         <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
292:           <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;[#{e.class}] #{e.message}&quot;</span>
293: 
294:           <span class="ruby-keyword kw">next</span>
295:         <span class="ruby-keyword kw">end</span>
296:       <span class="ruby-keyword kw">end</span>
297: 
298:       <span class="ruby-identifier">result</span>
299:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000483" class="method-detail">
        <a name="M000483"></a>

        <div class="method-heading">
          <a href="#M000483" class="method-signature">
          <span class="method-name">has_document_info?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns true if the document has a document information dictionary.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000483-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000483-source">
<pre>
    <span class="ruby-comment cmt"># File origami/metadata.rb, line 35</span>
35:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">has_document_info?</span>
36:       <span class="ruby-identifier">has_attr?</span> <span class="ruby-identifier">:Info</span> 
37:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000476" class="method-detail">
        <a name="M000476"></a>

        <div class="method-heading">
          <a href="#M000476" class="method-signature">
          <span class="method-name">has_form?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns true if the document contains an acrobat form.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000476-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000476-source">
<pre>
    <span class="ruby-comment cmt"># File origami/acroform.rb, line 33</span>
33:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">has_form?</span>
34:       (<span class="ruby-keyword kw">not</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-identifier">nil?</span>) <span class="ruby-keyword kw">and</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-identifier">has_field?</span> <span class="ruby-identifier">:AcroForm</span>
35:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000484" class="method-detail">
        <a name="M000484"></a>

        <div class="method-heading">
          <a href="#M000484" class="method-signature">
          <span class="method-name">has_metadata?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns true if the document has a catalog metadata stream.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000484-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000484-source">
<pre>
    <span class="ruby-comment cmt"># File origami/metadata.rb, line 42</span>
42:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">has_metadata?</span>
43:       <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-identifier">:Metadata</span> 
44:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000532" class="method-detail">
        <a name="M000532"></a>

        <div class="method-heading">
          <a href="#M000532" class="method-signature">
          <span class="method-name">has_usage_rights?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000532-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000532-source">
<pre>
     <span class="ruby-comment cmt"># File origami/signature.rb, line 217</span>
217:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">has_usage_rights?</span>
218:       
219:       <span class="ruby-comment cmt">#~ not self.Catalog.Perms.nil? and (not self.Catalog.Perms.UR3.nil? or not self.Catalog.Perms.UR.nil?)</span>
220:       <span class="ruby-value str">&quot;todo&quot;</span>
221:       
222:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000501" class="method-detail">
        <a name="M000501"></a>

        <div class="method-heading">
          <a href="#M000501" class="method-signature">
          <span class="method-name">indirect_objects</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Return an hash of indirect <a href="PDF.html#M000499">objects</a>. Updated
<a href="PDF.html#M000499">objects</a> appear only once.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000501-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000501-source">
<pre>
     <span class="ruby-comment cmt"># File origami/pdf.rb, line 412</span>
412:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">indirect_objects</span>
413:       <span class="ruby-ivar">@revisions</span>.<span class="ruby-identifier">inject</span>({}) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">set</span>, <span class="ruby-identifier">rev</span><span class="ruby-operator">|</span> <span class="ruby-identifier">set</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">rev</span>.<span class="ruby-identifier">body</span>) <span class="ruby-keyword kw">end</span>
414:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000503" class="method-detail">
        <a name="M000503"></a>

        <div class="method-heading">
          <span class="method-name">insert</span><span class="method-args">(object)</span>
        </div>
      
        <div class="method-description">
          <p>
Alias for #&lt;&lt;
</p>
        </div>
      </div>

      <div id="method-M000521" class="method-detail">
        <a name="M000521"></a>

        <div class="method-heading">
          <a href="#M000521" class="method-signature">
          <span class="method-name">insert_page</span><span class="method-args">(index, page)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000521-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000521-source">
<pre>
    <span class="ruby-comment cmt"># File origami/page.rb, line 44</span>
44:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">insert_page</span>(<span class="ruby-identifier">index</span>, <span class="ruby-identifier">page</span>)
45:       
46:       <span class="ruby-identifier">treeroot</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-constant">Pages</span>
47:       <span class="ruby-identifier">raise</span> <span class="ruby-constant">InvalidPDFError</span>, <span class="ruby-value str">&quot;No page tree&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">treeroot</span>.<span class="ruby-identifier">nil?</span>
48: 
49:       <span class="ruby-identifier">treeroot</span>.<span class="ruby-identifier">insert_page</span>(<span class="ruby-identifier">index</span>, <span class="ruby-identifier">page</span>)
50: 
51:       <span class="ruby-keyword kw">self</span>
52:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000479" class="method-detail">
        <a name="M000479"></a>

        <div class="method-heading">
          <a href="#M000479" class="method-signature">
          <span class="method-name">is_encrypted?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns whether the <a href="PDF.html">PDF</a> file is encrypted.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000479-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000479-source">
<pre>
    <span class="ruby-comment cmt"># File origami/encryption.rb, line 45</span>
45:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">is_encrypted?</span>
46:       <span class="ruby-identifier">has_attr?</span> <span class="ruby-identifier">:Encrypt</span>
47:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000527" class="method-detail">
        <a name="M000527"></a>

        <div class="method-heading">
          <a href="#M000527" class="method-signature">
          <span class="method-name">is_linearized?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns whether the current document is linearized.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000527-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000527-source">
<pre>
    <span class="ruby-comment cmt"># File origami/linearization.rb, line 33</span>
33:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">is_linearized?</span>
34:       <span class="ruby-keyword kw">begin</span>
35:         <span class="ruby-identifier">obj</span> = <span class="ruby-ivar">@revisions</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">body</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">sort_by</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">obj</span><span class="ruby-operator">|</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">file_offset</span>}.<span class="ruby-identifier">first</span>
36:       <span class="ruby-keyword kw">rescue</span>
37:         <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span>
38:       <span class="ruby-keyword kw">end</span>
39: 
40:       <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Dictionary</span>) <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-identifier">:Linearized</span>
41:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000530" class="method-detail">
        <a name="M000530"></a>

        <div class="method-heading">
          <a href="#M000530" class="method-signature">
          <span class="method-name">is_signed?</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns whether the document contains a digital signature.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000530-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000530-source">
<pre>
     <span class="ruby-comment cmt"># File origami/signature.rb, line 119</span>
119:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">is_signed?</span>
120:       
121:       <span class="ruby-comment cmt">#~ not self.Catalog.AcroForm.nil? and (self.Catalog.AcroForm[:SigFlags] &amp; InteractiveForm::SigFlags::SIGNATUREEXISTS) != 0</span>
122:       <span class="ruby-value str">&quot;todo&quot;</span>
123:       
124:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000496" class="method-detail">
        <a name="M000496"></a>

        <div class="method-heading">
          <a href="#M000496" class="method-signature">
          <span class="method-name">ls</span><span class="method-args">(*patterns)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an array of Objects whose name (in a <a
href="Dictionary.html">Dictionary</a>) is matching <em>pattern</em>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000496-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000496-source">
<pre>
     <span class="ruby-comment cmt"># File origami/pdf.rb, line 304</span>
304:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">ls</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">patterns</span>)
305:       <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">objects</span>(<span class="ruby-identifier">:include_keys</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">false</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">patterns</span>.<span class="ruby-identifier">empty?</span>
306: 
307:       <span class="ruby-identifier">result</span> = []
308: 
309:       <span class="ruby-identifier">patterns</span>.<span class="ruby-identifier">map!</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">pattern</span><span class="ruby-operator">|</span>
310:         <span class="ruby-identifier">pattern</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-operator">::</span><span class="ruby-constant">String</span>) <span class="ruby-operator">?</span> <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">escape</span>(<span class="ruby-identifier">pattern</span>)) <span class="ruby-operator">:</span> <span class="ruby-identifier">pattern</span>
311:       <span class="ruby-keyword kw">end</span>
312: 
313:       <span class="ruby-identifier">objects</span>(<span class="ruby-identifier">:only_keys</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">true</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span><span class="ruby-operator">|</span>
314:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">patterns</span>.<span class="ruby-identifier">any?</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">pattern</span><span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">pattern</span>) }
315:           <span class="ruby-identifier">value</span> = <span class="ruby-identifier">key</span>.<span class="ruby-identifier">parent</span>[<span class="ruby-identifier">key</span>]
316:           <span class="ruby-identifier">result</span> <span class="ruby-operator">&lt;&lt;</span> ( <span class="ruby-identifier">value</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Reference</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">value</span>.<span class="ruby-identifier">solve</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">value</span> )
317:         <span class="ruby-keyword kw">end</span>
318:       <span class="ruby-keyword kw">end</span>
319: 
320:       <span class="ruby-identifier">result</span>
321:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000497" class="method-detail">
        <a name="M000497"></a>

        <div class="method-heading">
          <a href="#M000497" class="method-signature">
          <span class="method-name">ls_no_follow</span><span class="method-args">(*patterns)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an array of Objects whose name (in a <a
href="Dictionary.html">Dictionary</a>) is matching <em>pattern</em>. Do not
follow references.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000497-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000497-source">
<pre>
     <span class="ruby-comment cmt"># File origami/pdf.rb, line 327</span>
327:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">ls_no_follow</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">patterns</span>)
328:       <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">objects</span>(<span class="ruby-identifier">:include_keys</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">false</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">patterns</span>.<span class="ruby-identifier">empty?</span>
329: 
330:       <span class="ruby-identifier">result</span> = []
331: 
332:       <span class="ruby-identifier">patterns</span>.<span class="ruby-identifier">map!</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">pattern</span><span class="ruby-operator">|</span>
333:         <span class="ruby-identifier">pattern</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-operator">::</span><span class="ruby-constant">String</span>) <span class="ruby-operator">?</span> <span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">Regexp</span>.<span class="ruby-identifier">escape</span>(<span class="ruby-identifier">pattern</span>)) <span class="ruby-operator">:</span> <span class="ruby-identifier">pattern</span>
334:       <span class="ruby-keyword kw">end</span>
335: 
336:       <span class="ruby-identifier">objects</span>(<span class="ruby-identifier">:only_keys</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">true</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span><span class="ruby-operator">|</span>
337:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">patterns</span>.<span class="ruby-identifier">any?</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">pattern</span><span class="ruby-operator">|</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">value</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">match</span>(<span class="ruby-identifier">pattern</span>) }
338:           <span class="ruby-identifier">value</span> = <span class="ruby-identifier">key</span>.<span class="ruby-identifier">parent</span>[<span class="ruby-identifier">key</span>]
339:           <span class="ruby-identifier">result</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">value</span>
340:         <span class="ruby-keyword kw">end</span>
341:       <span class="ruby-keyword kw">end</span>
342: 
343:       <span class="ruby-identifier">result</span>
344:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000499" class="method-detail">
        <a name="M000499"></a>

        <div class="method-heading">
          <a href="#M000499" class="method-signature">
          <span class="method-name">objects</span><span class="method-args">(params = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an array of <a href="PDF.html#M000499">objects</a> embedded in the
<a href="PDF.html">PDF</a> body.
</p>
<table>
<tr><td valign="top"><em>include_objstm</em>:</td><td>Whether it shall return <a href="PDF.html#M000499">objects</a> embedded in
object streams.

</td></tr>
</table>
<p>
Note : Shall return to an iterator for Ruby 1.9 comp.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000499-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000499-source">
<pre>
     <span class="ruby-comment cmt"># File origami/pdf.rb, line 368</span>
368:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">objects</span>(<span class="ruby-identifier">params</span> = {})
369:       
370:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">append_subobj</span>(<span class="ruby-identifier">root</span>, <span class="ruby-identifier">objset</span>, <span class="ruby-identifier">opts</span>)
371:         
372:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">objset</span>.<span class="ruby-identifier">find</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">o</span><span class="ruby-operator">|</span> <span class="ruby-identifier">root</span>.<span class="ruby-identifier">equal?</span>(<span class="ruby-identifier">o</span>) }.<span class="ruby-identifier">nil?</span>
373:           <span class="ruby-identifier">objset</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">root</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:only_keys</span>]
374: 
375:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">root</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Dictionary</span>)
376:             <span class="ruby-identifier">root</span>.<span class="ruby-identifier">each_pair</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">name</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
377:               <span class="ruby-identifier">objset</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">name</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:only_keys</span>]
378: 
379:               <span class="ruby-identifier">append_subobj</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">objset</span>, <span class="ruby-identifier">opts</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:include_keys</span>] <span class="ruby-keyword kw">and</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:only_keys</span>]
380:               <span class="ruby-identifier">append_subobj</span>(<span class="ruby-identifier">value</span>, <span class="ruby-identifier">objset</span>, <span class="ruby-identifier">opts</span>)
381:             }
382:           <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">root</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>) <span class="ruby-keyword kw">or</span> (<span class="ruby-identifier">root</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">ObjectStream</span>) <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:include_objectstreams</span>])
383:             <span class="ruby-identifier">root</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">subobj</span><span class="ruby-operator">|</span> <span class="ruby-identifier">append_subobj</span>(<span class="ruby-identifier">subobj</span>, <span class="ruby-identifier">objset</span>, <span class="ruby-identifier">opts</span>) }
384:           <span class="ruby-keyword kw">end</span>
385:         <span class="ruby-keyword kw">end</span>
386:       <span class="ruby-keyword kw">end</span>
387: 
388:       <span class="ruby-identifier">options</span> =
389:       {
390:         <span class="ruby-identifier">:include_objectstreams</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">true</span>,
391:         <span class="ruby-identifier">:include_keys</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">true</span>,
392:         <span class="ruby-identifier">:only_keys</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">false</span>
393:       }
394:       <span class="ruby-identifier">options</span>.<span class="ruby-identifier">update</span>(<span class="ruby-identifier">params</span>)
395: 
396:       <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:include_keys</span>] <span class="ruby-operator">|=</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:only_keys</span>]
397:       
398:       <span class="ruby-identifier">objset</span> = []
399:       <span class="ruby-ivar">@revisions</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">revision</span><span class="ruby-operator">|</span>
400:         <span class="ruby-identifier">revision</span>.<span class="ruby-identifier">body</span>.<span class="ruby-identifier">each_value</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">object</span><span class="ruby-operator">|</span>
401:             <span class="ruby-identifier">append_subobj</span>(<span class="ruby-identifier">object</span>, <span class="ruby-identifier">objset</span>, <span class="ruby-identifier">options</span>)
402:         }
403:       }
404:       
405:       <span class="ruby-identifier">objset</span>
406:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000517" class="method-detail">
        <a name="M000517"></a>

        <div class="method-heading">
          <a href="#M000517" class="method-signature">
          <span class="method-name">onDocumentClose</span><span class="method-args">(action)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sets an action to run on document closing.
</p>
<table>
<tr><td valign="top"><em>action</em>:</td><td>A JavaScript <a href="Action.html">Action</a> <a
href="Object.html">Object</a>.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000517-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000517-source">
<pre>
     <span class="ruby-comment cmt"># File origami/catalog.rb, line 89</span>
 89:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">onDocumentClose</span>(<span class="ruby-identifier">action</span>)
 90:       
 91:       <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">action</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Action</span><span class="ruby-operator">::</span><span class="ruby-constant">JavaScript</span>)
 92:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-value str">&quot;An Action::JavaScript object must be passed.&quot;</span>
 93:       <span class="ruby-keyword kw">end</span>
 94:       
 95:       <span class="ruby-keyword kw">unless</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>
 96:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">InvalidPDFError</span>, <span class="ruby-value str">&quot;A catalog object must exist to add this action.&quot;</span>
 97:       <span class="ruby-keyword kw">end</span>
 98:       
 99:       <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-constant">AA</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">CatalogAdditionalActions</span>.<span class="ruby-identifier">new</span>
100:       <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-constant">AA</span>.<span class="ruby-constant">WC</span> = <span class="ruby-identifier">action</span>
101:       
102:       <span class="ruby-keyword kw">self</span>
103:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000516" class="method-detail">
        <a name="M000516"></a>

        <div class="method-heading">
          <a href="#M000516" class="method-signature">
          <span class="method-name">onDocumentOpen</span><span class="method-args">(action)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sets an action to run on document opening.
</p>
<table>
<tr><td valign="top"><em>action</em>:</td><td>An <a href="Action.html">Action</a> <a href="Object.html">Object</a>.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000516-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000516-source">
<pre>
    <span class="ruby-comment cmt"># File origami/catalog.rb, line 70</span>
70:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">onDocumentOpen</span>(<span class="ruby-identifier">action</span>)   
71:       
72:       <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">action</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Action</span>)
73:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-value str">&quot;An Action object must be passed.&quot;</span>
74:       <span class="ruby-keyword kw">end</span>
75:       
76:       <span class="ruby-keyword kw">unless</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>
77:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">InvalidPDFError</span>, <span class="ruby-value str">&quot;A catalog object must exist to add this action.&quot;</span>
78:       <span class="ruby-keyword kw">end</span>
79:       
80:       <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-constant">OpenAction</span> = <span class="ruby-identifier">action</span>
81:       
82:       <span class="ruby-keyword kw">self</span>
83:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000518" class="method-detail">
        <a name="M000518"></a>

        <div class="method-heading">
          <a href="#M000518" class="method-signature">
          <span class="method-name">onDocumentPrint</span><span class="method-args">(action)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sets an action to run on document printing.
</p>
<table>
<tr><td valign="top"><em>action</em>:</td><td>A JavaScript <a href="Action.html">Action</a> <a
href="Object.html">Object</a>.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000518-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000518-source">
<pre>
     <span class="ruby-comment cmt"># File origami/catalog.rb, line 109</span>
109:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">onDocumentPrint</span>(<span class="ruby-identifier">action</span>)
110:       
111:       <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">action</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Action</span><span class="ruby-operator">::</span><span class="ruby-constant">JavaScript</span>)
112:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-value str">&quot;An Action::JavaScript object must be passed.&quot;</span>
113:       <span class="ruby-keyword kw">end</span>
114:       
115:       <span class="ruby-keyword kw">unless</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>
116:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">InvalidPDFError</span>, <span class="ruby-value str">&quot;A catalog object must exist to add this action.&quot;</span>
117:       <span class="ruby-keyword kw">end</span>
118:       
119:       <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-constant">AA</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">CatalogAdditionalActions</span>.<span class="ruby-identifier">new</span>
120:       <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-constant">AA</span>.<span class="ruby-constant">WP</span> = <span class="ruby-identifier">action</span>
121:       
122:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000522" class="method-detail">
        <a name="M000522"></a>

        <div class="method-heading">
          <a href="#M000522" class="method-signature">
          <span class="method-name">pages</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns an array of <a href="Page.html">Page</a>
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000522-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000522-source">
<pre>
    <span class="ruby-comment cmt"># File origami/page.rb, line 57</span>
57:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">pages</span>
58:       <span class="ruby-keyword kw">return</span> [] <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">not</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span> <span class="ruby-keyword kw">or</span> <span class="ruby-keyword kw">not</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-constant">Pages</span>
59:       
60:       <span class="ruby-identifier">root</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-constant">Pages</span>
61:       <span class="ruby-keyword kw">return</span> [] <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">root</span>.<span class="ruby-identifier">nil?</span>
62: 
63:       <span class="ruby-identifier">root</span>.<span class="ruby-identifier">children</span>
64:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000512" class="method-detail">
        <a name="M000512"></a>

        <div class="method-heading">
          <a href="#M000512" class="method-signature">
          <span class="method-name">physicalize</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Converts a logical <a href="PDF.html">PDF</a> view into a physical view
ready for writing.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000512-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000512-source">
<pre>
     <span class="ruby-comment cmt"># File origami/pdf.rb, line 838</span>
838:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">physicalize</span>
839:      
840:       <span class="ruby-comment cmt">#</span>
841:       <span class="ruby-comment cmt"># Indirect objects are added to the revision and assigned numbers.</span>
842:       <span class="ruby-comment cmt">#</span>
843:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">build</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-identifier">revision</span>) <span class="ruby-comment cmt">#:nodoc:</span>
844: 
845:         <span class="ruby-comment cmt">#</span>
846:         <span class="ruby-comment cmt"># Finalize any subobjects before building the stream.</span>
847:         <span class="ruby-comment cmt">#</span>
848:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">ObjectStream</span>)
849:           <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">subobj</span><span class="ruby-operator">|</span>
850:             <span class="ruby-identifier">build</span>(<span class="ruby-identifier">subobj</span>, <span class="ruby-identifier">revision</span>)
851:           }
852:         <span class="ruby-keyword kw">end</span>
853:   
854:         <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">pre_build</span>
855: 
856:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Dictionary</span>) <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Array</span>)
857:             
858:             <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">map!</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">subobj</span><span class="ruby-operator">|</span>
859:               <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">subobj</span>.<span class="ruby-identifier">is_indirect?</span>
860:                 <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">get_object</span>(<span class="ruby-identifier">subobj</span>.<span class="ruby-identifier">reference</span>)
861:                   <span class="ruby-identifier">subobj</span>.<span class="ruby-identifier">reference</span>
862:                 <span class="ruby-keyword kw">else</span>
863:                   <span class="ruby-identifier">ref</span> = <span class="ruby-identifier">add_to_revision</span>(<span class="ruby-identifier">subobj</span>, <span class="ruby-identifier">revision</span>)
864:                   <span class="ruby-identifier">build</span>(<span class="ruby-identifier">subobj</span>, <span class="ruby-identifier">revision</span>)
865:                   <span class="ruby-identifier">ref</span>
866:                 <span class="ruby-keyword kw">end</span>
867:               <span class="ruby-keyword kw">else</span>
868:                 <span class="ruby-identifier">subobj</span>
869:               <span class="ruby-keyword kw">end</span>
870:             }
871:             
872:             <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">subobj</span><span class="ruby-operator">|</span>
873:               <span class="ruby-identifier">build</span>(<span class="ruby-identifier">subobj</span>, <span class="ruby-identifier">revision</span>)
874:             }
875:             
876:         <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Stream</span>)
877:           <span class="ruby-identifier">build</span>(<span class="ruby-identifier">obj</span>.<span class="ruby-identifier">dictionary</span>, <span class="ruby-identifier">revision</span>)
878:         <span class="ruby-keyword kw">end</span>
879: 
880:         <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">post_build</span>
881:         
882:       <span class="ruby-keyword kw">end</span>
883:       
884:       <span class="ruby-identifier">all_indirect_objects</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">obj</span>, <span class="ruby-identifier">revision</span><span class="ruby-operator">|</span>
885:           <span class="ruby-identifier">build</span>(<span class="ruby-identifier">obj</span>, <span class="ruby-identifier">revision</span>)          
886:       }
887:       
888:       <span class="ruby-keyword kw">self</span>
889:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000508" class="method-detail">
        <a name="M000508"></a>

        <div class="method-heading">
          <a href="#M000508" class="method-signature">
          <span class="method-name">rebuildxrefs</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Compute and update <a href="XRef/Section.html">XRef::Section</a> for each
<a href="PDF/Revision.html">Revision</a>.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000508-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000508-source">
<pre>
     <span class="ruby-comment cmt"># File origami/pdf.rb, line 685</span>
685:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">rebuildxrefs</span>
686:       
687:       <span class="ruby-identifier">size</span> = <span class="ruby-value">0</span>
688:       <span class="ruby-identifier">startxref</span> = <span class="ruby-ivar">@header</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">size</span>
689:       
690:       <span class="ruby-ivar">@revisions</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">revision</span><span class="ruby-operator">|</span>
691:       
692:         <span class="ruby-identifier">revision</span>.<span class="ruby-identifier">body</span>.<span class="ruby-identifier">each_value</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">object</span><span class="ruby-operator">|</span>
693:           <span class="ruby-identifier">startxref</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">object</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">size</span>
694:         }
695:         
696:         <span class="ruby-identifier">size</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">revision</span>.<span class="ruby-identifier">body</span>.<span class="ruby-identifier">size</span>
697:         <span class="ruby-identifier">revision</span>.<span class="ruby-identifier">xreftable</span> = <span class="ruby-identifier">buildxrefs</span>(<span class="ruby-identifier">revision</span>.<span class="ruby-identifier">body</span>.<span class="ruby-identifier">values</span>)
698:         
699:         <span class="ruby-identifier">revision</span>.<span class="ruby-identifier">trailer</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">Trailer</span>.<span class="ruby-identifier">new</span>
700:         <span class="ruby-identifier">revision</span>.<span class="ruby-identifier">trailer</span>.<span class="ruby-constant">Size</span> = <span class="ruby-identifier">size</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
701:         <span class="ruby-identifier">revision</span>.<span class="ruby-identifier">trailer</span>.<span class="ruby-identifier">startxref</span> = <span class="ruby-identifier">startxref</span>
702:         
703:         <span class="ruby-identifier">startxref</span> <span class="ruby-operator">+=</span> <span class="ruby-identifier">revision</span>.<span class="ruby-identifier">xreftable</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">revision</span>.<span class="ruby-identifier">trailer</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">size</span>
704:       }
705:       
706:       <span class="ruby-keyword kw">self</span>
707:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000519" class="method-detail">
        <a name="M000519"></a>

        <div class="method-heading">
          <a href="#M000519" class="method-signature">
          <span class="method-name">register</span><span class="method-args">(root, name, value)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Registers an object into a specific Names root dictionary.
</p>
<table>
<tr><td valign="top"><em>root</em>:</td><td>The root dictionary (see <a href="Names/Root.html">Names::Root</a>)

</td></tr>
<tr><td valign="top"><em>name</em>:</td><td>The value name.

</td></tr>
<tr><td valign="top"><em>value</em>:</td><td>The value to associate with this name.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000519-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000519-source">
<pre>
     <span class="ruby-comment cmt"># File origami/catalog.rb, line 130</span>
130:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">register</span>(<span class="ruby-identifier">root</span>, <span class="ruby-identifier">name</span>, <span class="ruby-identifier">value</span>)
131:       
132:       <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-constant">Names</span>.<span class="ruby-identifier">nil?</span>
133:         <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-constant">Names</span> = <span class="ruby-constant">Names</span>.<span class="ruby-identifier">new</span>
134:       <span class="ruby-keyword kw">end</span>
135:       
136:       <span class="ruby-identifier">value</span>.<span class="ruby-identifier">set_indirect</span>(<span class="ruby-keyword kw">true</span>)
137:       
138:       <span class="ruby-identifier">namesroot</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-constant">Names</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">root</span>)
139:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">namesroot</span>.<span class="ruby-identifier">nil?</span>
140:         <span class="ruby-identifier">names</span> = <span class="ruby-constant">NameTreeNode</span>.<span class="ruby-identifier">new</span>({<span class="ruby-identifier">:Names</span> =<span class="ruby-operator">&gt;</span> [] })
141:         <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-constant">Names</span>.<span class="ruby-identifier">send</span>((<span class="ruby-identifier">root</span>.<span class="ruby-identifier">id2name</span> <span class="ruby-operator">+</span> <span class="ruby-value str">&quot;=&quot;</span>).<span class="ruby-identifier">to_sym</span>, (<span class="ruby-keyword kw">self</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">names</span>))
142:         
143:         <span class="ruby-identifier">names</span>.<span class="ruby-constant">Names</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">name</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">value</span>
144:       <span class="ruby-keyword kw">else</span>
145:         <span class="ruby-identifier">namesroot</span>.<span class="ruby-constant">Names</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">name</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">value</span>
146:       <span class="ruby-keyword kw">end</span>
147:       
148:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000510" class="method-detail">
        <a name="M000510"></a>

        <div class="method-heading">
          <a href="#M000510" class="method-signature">
          <span class="method-name">remove_revision</span><span class="method-args">(index)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Removes a whole document revision.
</p>
<table>
<tr><td valign="top"><em>index</em>:</td><td><a href="PDF/Revision.html">Revision</a> index, first is 0.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000510-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000510-source">
<pre>
     <span class="ruby-comment cmt"># File origami/pdf.rb, line 727</span>
727:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">remove_revision</span>(<span class="ruby-identifier">index</span>)
728:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">index</span> <span class="ruby-operator">&lt;</span> <span class="ruby-value">0</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">index</span> <span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@revisions</span>.<span class="ruby-identifier">size</span>
729:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">IndexError</span>, <span class="ruby-value str">&quot;Not a valid revision index&quot;</span>
730:       <span class="ruby-keyword kw">end</span>
731: 
732:       <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@revisions</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>
733:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">InvalidPDFError</span>, <span class="ruby-value str">&quot;Cannot remove last revision&quot;</span>
734:       <span class="ruby-keyword kw">end</span>
735: 
736:       <span class="ruby-ivar">@revisions</span>.<span class="ruby-identifier">delete_at</span>(<span class="ruby-identifier">index</span>)
737:       <span class="ruby-keyword kw">self</span>
738:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000525" class="method-detail">
        <a name="M000525"></a>

        <div class="method-heading">
          <a href="#M000525" class="method-signature">
          <span class="method-name">remove_xrefs</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Tries to strip any xrefs information off the document.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000525-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000525-source">
<pre>
    <span class="ruby-comment cmt"># File origami/xreftable.rb, line 29</span>
29:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">remove_xrefs</span>
30:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete_xrefstm</span>(<span class="ruby-identifier">xrefstm</span>)
31:         <span class="ruby-identifier">prev</span> = <span class="ruby-identifier">xrefstm</span>.<span class="ruby-constant">Prev</span>
32:         <span class="ruby-identifier">delete_object</span>(<span class="ruby-identifier">xrefstm</span>.<span class="ruby-identifier">reference</span>)
33: 
34:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">prev</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Integer</span>) <span class="ruby-keyword kw">and</span> (<span class="ruby-identifier">prev_stm</span> = <span class="ruby-identifier">get_object_by_offset</span>(<span class="ruby-identifier">prev</span>)).<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">XRefStream</span>)
35:           <span class="ruby-identifier">delete_xrefstm</span>(<span class="ruby-identifier">prev_stm</span>)
36:         <span class="ruby-keyword kw">end</span>
37:       <span class="ruby-keyword kw">end</span>
38: 
39:       <span class="ruby-ivar">@revisions</span>.<span class="ruby-identifier">reverse_each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">rev</span><span class="ruby-operator">|</span>
40:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">rev</span>.<span class="ruby-identifier">has_xrefstm?</span>
41:           <span class="ruby-identifier">delete_xrefstm</span>(<span class="ruby-identifier">rev</span>.<span class="ruby-identifier">xrefstm</span>)
42:         <span class="ruby-keyword kw">end</span>
43:         
44:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">rev</span>.<span class="ruby-identifier">trailer</span>.<span class="ruby-identifier">has_dictionary?</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">rev</span>.<span class="ruby-identifier">trailer</span>.<span class="ruby-constant">XRefStm</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Integer</span>)
45:           <span class="ruby-identifier">xrefstm</span> = <span class="ruby-identifier">get_object_by_offset</span>(<span class="ruby-identifier">rev</span>.<span class="ruby-identifier">trailer</span>.<span class="ruby-constant">XRefStm</span>)
46: 
47:           <span class="ruby-identifier">delete_xrefstm</span>(<span class="ruby-identifier">xrefstm</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">xrefstm</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">XRefStream</span>)
48:         <span class="ruby-keyword kw">end</span>
49: 
50:         <span class="ruby-identifier">rev</span>.<span class="ruby-identifier">xrefstm</span> = <span class="ruby-identifier">rev</span>.<span class="ruby-identifier">xreftable</span> = <span class="ruby-keyword kw">nil</span>
51:       <span class="ruby-keyword kw">end</span>
52:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000492" class="method-detail">
        <a name="M000492"></a>

        <div class="method-heading">
          <a href="#M000492" class="method-signature">
          <span class="method-name">save</span><span class="method-args">(file, params = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Saves the current file as its current filename.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000492-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000492-source">
<pre>
     <span class="ruby-comment cmt"># File origami/pdf.rb, line 218</span>
218:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">save</span>(<span class="ruby-identifier">file</span>, <span class="ruby-identifier">params</span> = {})
219:       
220:       <span class="ruby-identifier">options</span> = 
221:       {
222:         <span class="ruby-identifier">:delinearize</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">true</span>,
223:         <span class="ruby-identifier">:recompile</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">true</span>,
224:       }
225:       <span class="ruby-identifier">options</span>.<span class="ruby-identifier">update</span>(<span class="ruby-identifier">params</span>)
226: 
227:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">file</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:write</span>)
228:         <span class="ruby-identifier">fd</span> = <span class="ruby-identifier">file</span>
229:       <span class="ruby-keyword kw">else</span>
230:         <span class="ruby-identifier">fd</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">file</span>, <span class="ruby-value str">'w'</span>).<span class="ruby-identifier">binmode</span>
231:       <span class="ruby-keyword kw">end</span>
232:       
233:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">delinearize!</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:delinearize</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">is_linearized?</span>
234:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">compile</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:recompile</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span>
235: 
236:       <span class="ruby-identifier">fd</span>.<span class="ruby-identifier">write</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_bin</span>(<span class="ruby-identifier">options</span>)
237:       <span class="ruby-identifier">fd</span>.<span class="ruby-identifier">close</span>
238:       
239:       <span class="ruby-keyword kw">self</span>
240:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000494" class="method-detail">
        <a name="M000494"></a>

        <div class="method-heading">
          <a href="#M000494" class="method-signature">
          <span class="method-name">save_upto</span><span class="method-args">(revision, filename)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Saves the file up to given revision number. This can be useful to visualize
the modifications over different incremental updates.
</p>
<table>
<tr><td valign="top"><em>revision</em>:</td><td>The revision number to <a href="PDF.html#M000492">save</a>.

</td></tr>
<tr><td valign="top"><em>filename</em>:</td><td>The path where to <a href="PDF.html#M000492">save</a> this <a
href="PDF.html">PDF</a>.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000494-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000494-source">
<pre>
     <span class="ruby-comment cmt"># File origami/pdf.rb, line 265</span>
265:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">save_upto</span>(<span class="ruby-identifier">revision</span>, <span class="ruby-identifier">filename</span>)
266:       <span class="ruby-identifier">saveas</span>(<span class="ruby-identifier">filename</span>, <span class="ruby-identifier">:up_to_revision</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">revision</span>)  
267:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000493" class="method-detail">
        <a name="M000493"></a>

        <div class="method-heading">
          <a href="#M000493" class="method-signature">
          <span class="method-name">saveas</span><span class="method-args">(filename, params = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sets the current filename to the argument given, then <a
href="PDF.html#M000492">save</a> it.
</p>
<table>
<tr><td valign="top"><em>filename</em>:</td><td>The path where to <a href="PDF.html#M000492">save</a> this <a
href="PDF.html">PDF</a>.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000493-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000493-source">
<pre>
     <span class="ruby-comment cmt"># File origami/pdf.rb, line 246</span>
246:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">saveas</span>(<span class="ruby-identifier">filename</span>, <span class="ruby-identifier">params</span> = {})
247:       
248:       <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">frozen?</span>
249:         <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:recompile</span>] = <span class="ruby-identifier">params</span>[<span class="ruby-identifier">:rebuildxrefs</span>] = <span class="ruby-keyword kw">false</span>
250:         <span class="ruby-identifier">save</span>(<span class="ruby-identifier">filename</span>, <span class="ruby-identifier">params</span>)
251:       <span class="ruby-keyword kw">else</span> 
252:         <span class="ruby-ivar">@filename</span> = <span class="ruby-identifier">filename</span>
253:         <span class="ruby-identifier">save</span>(<span class="ruby-identifier">filename</span>, <span class="ruby-identifier">params</span>)
254:       <span class="ruby-keyword kw">end</span>
255:       
256:       <span class="ruby-keyword kw">self</span>
257:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000490" class="method-detail">
        <a name="M000490"></a>

        <div class="method-heading">
          <a href="#M000490" class="method-signature">
          <span class="method-name">serialize</span><span class="method-args">(filename)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Serializes the current <a href="PDF.html">PDF</a>
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000490-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000490-source">
<pre>
     <span class="ruby-comment cmt"># File origami/pdf.rb, line 200</span>
200:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">serialize</span>(<span class="ruby-identifier">filename</span>)
201:         <span class="ruby-constant">Zlib</span><span class="ruby-operator">::</span><span class="ruby-constant">GzipWriter</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">filename</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">gz</span><span class="ruby-operator">|</span>
202:           <span class="ruby-identifier">gz</span>.<span class="ruby-identifier">write</span> <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">dump</span>(<span class="ruby-keyword kw">self</span>)
203:         }
204:         
205:         <span class="ruby-keyword kw">self</span>
206:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000513" class="method-detail">
        <a name="M000513"></a>

        <div class="method-heading">
          <a href="#M000513" class="method-signature">
          <span class="method-name">set_extension_level</span><span class="method-args">(version, level)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sets <a href="PDF.html">PDF</a> extension level and version. Only supported
values are &quot;1.7&quot; and 3.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000513-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000513-source">
<pre>
    <span class="ruby-comment cmt"># File origami/catalog.rb, line 33</span>
33:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_extension_level</span>(<span class="ruby-identifier">version</span>, <span class="ruby-identifier">level</span>)
34:       <span class="ruby-identifier">exts</span> = (<span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-constant">Extensions</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">Extensions</span>.<span class="ruby-identifier">new</span>)
35: 
36:       <span class="ruby-identifier">exts</span>[<span class="ruby-identifier">:ADBE</span>] = <span class="ruby-constant">DeveloperExtension</span>.<span class="ruby-identifier">new</span>
37:       <span class="ruby-identifier">exts</span>[<span class="ruby-identifier">:ADBE</span>].<span class="ruby-constant">BaseVersion</span> = <span class="ruby-constant">Name</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">version</span>)
38:       <span class="ruby-identifier">exts</span>[<span class="ruby-identifier">:ADBE</span>].<span class="ruby-constant">ExtensionLevel</span> = <span class="ruby-identifier">level</span>
39: 
40:       <span class="ruby-keyword kw">self</span>
41:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000529" class="method-detail">
        <a name="M000529"></a>

        <div class="method-heading">
          <a href="#M000529" class="method-signature">
          <span class="method-name">sign</span><span class="method-args">(certificate, key, ca = [], annotation = nil, location = nil, contact = nil, reason = nil)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Sign the document with the given key and x509 certificate.
</p>
<table>
<tr><td valign="top"><em>certificate</em>:</td><td>The X509 certificate containing the public key.

</td></tr>
<tr><td valign="top"><em>key</em>:</td><td>The private key associated with the certificate.

</td></tr>
<tr><td valign="top"><em>ca</em>:</td><td>Optional CA certificates used to <a href="PDF.html#M000529">sign</a> the
user certificate.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000529-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000529-source">
<pre>
     <span class="ruby-comment cmt"># File origami/signature.rb, line 34</span>
 34:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sign</span>(<span class="ruby-identifier">certificate</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">ca</span> = [], <span class="ruby-identifier">annotation</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">location</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">contact</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">reason</span> = <span class="ruby-keyword kw">nil</span>)
 35:       
 36:       <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">certificate</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">X509</span><span class="ruby-operator">::</span><span class="ruby-constant">Certificate</span>)
 37:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-value str">&quot;A OpenSSL::X509::Certificate object must be passed.&quot;</span>
 38:       <span class="ruby-keyword kw">end</span>
 39:       
 40:       <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">RSA</span>)
 41:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-value str">&quot;A OpenSSL::PKey::RSA object must be passed.&quot;</span>
 42:       <span class="ruby-keyword kw">end</span>
 43:       
 44:       <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">ca</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-operator">::</span><span class="ruby-constant">Array</span>)
 45:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-value str">&quot;Expected an Array of CA certificate.&quot;</span>
 46:       <span class="ruby-keyword kw">end</span>
 47:       
 48:       <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">annotation</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">annotation</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Annotation</span><span class="ruby-operator">::</span><span class="ruby-constant">Widget</span><span class="ruby-operator">::</span><span class="ruby-constant">Signature</span>)
 49:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-value str">&quot;Expected a Annotation::Widget::Signature object.&quot;</span>
 50:       <span class="ruby-keyword kw">end</span>
 51:       
 52:       <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">signfield_size</span>(<span class="ruby-identifier">certificate</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">ca</span> = []) <span class="ruby-comment cmt">#;nodoc:</span>
 53:         <span class="ruby-identifier">datatest</span> = <span class="ruby-value str">&quot;abcdefghijklmnopqrstuvwxyz&quot;</span>
 54:         <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKCS7</span>.<span class="ruby-identifier">sign</span>(<span class="ruby-identifier">certificate</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">datatest</span>, <span class="ruby-identifier">ca</span>, <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKCS7</span><span class="ruby-operator">::</span><span class="ruby-constant">DETACHED</span> <span class="ruby-operator">|</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKCS7</span><span class="ruby-operator">::</span><span class="ruby-constant">BINARY</span>).<span class="ruby-identifier">to_der</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">+</span> <span class="ruby-value">128</span>
 55:       <span class="ruby-keyword kw">end</span>
 56:       
 57:       <span class="ruby-identifier">digsig</span> = <span class="ruby-constant">Signature</span><span class="ruby-operator">::</span><span class="ruby-constant">DigitalSignature</span>.<span class="ruby-identifier">new</span>.<span class="ruby-identifier">set_indirect</span>(<span class="ruby-keyword kw">true</span>)
 58:      
 59:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">annotation</span>.<span class="ruby-identifier">nil?</span>
 60:         <span class="ruby-identifier">annotation</span> = <span class="ruby-constant">Annotation</span><span class="ruby-operator">::</span><span class="ruby-constant">Widget</span><span class="ruby-operator">::</span><span class="ruby-constant">Signature</span>.<span class="ruby-identifier">new</span>
 61:         <span class="ruby-identifier">annotation</span>.<span class="ruby-constant">Rect</span> = <span class="ruby-constant">Rectangle</span>[<span class="ruby-identifier">:llx</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span><span class="ruby-value">.0</span>, <span class="ruby-identifier">:lly</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span><span class="ruby-value">.0</span>, <span class="ruby-identifier">:urx</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span><span class="ruby-value">.0</span>, <span class="ruby-identifier">:ury</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">0</span><span class="ruby-value">.0</span>]        
 62:       <span class="ruby-keyword kw">end</span>
 63:       
 64:       <span class="ruby-identifier">annotation</span>.<span class="ruby-constant">V</span> = <span class="ruby-identifier">digsig</span> ;
 65:       <span class="ruby-identifier">add_fields</span>(<span class="ruby-identifier">annotation</span>)
 66:       <span class="ruby-keyword kw">self</span>.<span class="ruby-constant">Catalog</span>.<span class="ruby-constant">AcroForm</span>.<span class="ruby-constant">SigFlags</span> = <span class="ruby-constant">InteractiveForm</span><span class="ruby-operator">::</span><span class="ruby-constant">SigFlags</span><span class="ruby-operator">::</span><span class="ruby-constant">SIGNATURESEXIST</span> <span class="ruby-operator">|</span> <span class="ruby-constant">InteractiveForm</span><span class="ruby-operator">::</span><span class="ruby-constant">SigFlags</span><span class="ruby-operator">::</span><span class="ruby-constant">APPENDONLY</span>
 67:       
 68:       <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">Type</span> = <span class="ruby-identifier">:Sig</span> <span class="ruby-comment cmt">#:nodoc:</span>
 69:       <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">Contents</span> = <span class="ruby-constant">HexaString</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">&quot;\x00&quot;</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">signfield_size</span>(<span class="ruby-identifier">certificate</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">ca</span>)) <span class="ruby-comment cmt">#:nodoc:</span>
 70:       <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">Filter</span> = <span class="ruby-constant">Name</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">&quot;Adobe.PPKMS&quot;</span>) <span class="ruby-comment cmt">#:nodoc:</span>
 71:       <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">SubFilter</span> = <span class="ruby-constant">Name</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value str">&quot;adbe.pkcs7.detached&quot;</span>) <span class="ruby-comment cmt">#:nodoc:</span>
 72:       <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">ByteRange</span> = [<span class="ruby-value">0</span>, <span class="ruby-value">0</span>, <span class="ruby-value">0</span>, <span class="ruby-value">0</span>] <span class="ruby-comment cmt">#:nodoc:</span>
 73:       
 74:       <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">Location</span> = <span class="ruby-constant">HexaString</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">location</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">location</span>
 75:       <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">ContactInfo</span> = <span class="ruby-constant">HexaString</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">contact</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">contact</span>
 76:       <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">Reason</span> = <span class="ruby-constant">HexaString</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">reason</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">reason</span>
 77:       
 78:       <span class="ruby-comment cmt">#</span>
 79:       <span class="ruby-comment cmt">#  Flattening the PDF to get file view.</span>
 80:       <span class="ruby-comment cmt">#</span>
 81:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">compile</span>
 82:       
 83:       <span class="ruby-comment cmt">#</span>
 84:       <span class="ruby-comment cmt"># Creating an empty Xref table to compute signature byte range.</span>
 85:       <span class="ruby-comment cmt">#</span>
 86:       <span class="ruby-identifier">rebuild_dummy_xrefs</span>
 87:       
 88:       <span class="ruby-identifier">sigoffset</span> = <span class="ruby-identifier">get_object_offset</span>(<span class="ruby-identifier">digsig</span>.<span class="ruby-identifier">no</span>, <span class="ruby-identifier">digsig</span>.<span class="ruby-identifier">generation</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">digsig</span>.<span class="ruby-identifier">sigOffset</span>
 89:       
 90:       <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">ByteRange</span>[<span class="ruby-value">0</span>] = <span class="ruby-value">0</span> 
 91:       <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">ByteRange</span>[<span class="ruby-value">1</span>] = <span class="ruby-identifier">sigoffset</span>
 92:       <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">ByteRange</span>[<span class="ruby-value">2</span>] = <span class="ruby-identifier">sigoffset</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">Contents</span>.<span class="ruby-identifier">size</span>
 93:       
 94:       <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">ByteRange</span>[<span class="ruby-value">3</span>] = <span class="ruby-identifier">filesize</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">ByteRange</span>[<span class="ruby-value">2</span>] <span class="ruby-keyword kw">until</span> <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">ByteRange</span>[<span class="ruby-value">3</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">filesize</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">ByteRange</span>[<span class="ruby-value">2</span>]
 95:       
 96:       <span class="ruby-comment cmt"># From that point the file size remains constant</span>
 97:       
 98:       <span class="ruby-comment cmt">#</span>
 99:       <span class="ruby-comment cmt"># Correct Xrefs variations caused by ByteRange modifications.</span>
100:       <span class="ruby-comment cmt">#</span>
101:       <span class="ruby-identifier">rebuildxrefs</span>
102:       
103:       <span class="ruby-identifier">filedata</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_bin</span>
104:       <span class="ruby-identifier">signable_data</span> = <span class="ruby-identifier">filedata</span>[<span class="ruby-identifier">digsig</span>.<span class="ruby-constant">ByteRange</span>[<span class="ruby-value">0</span>],<span class="ruby-identifier">digsig</span>.<span class="ruby-constant">ByteRange</span>[<span class="ruby-value">1</span>]] <span class="ruby-operator">+</span> <span class="ruby-identifier">filedata</span>[<span class="ruby-identifier">digsig</span>.<span class="ruby-constant">ByteRange</span>[<span class="ruby-value">2</span>],<span class="ruby-identifier">digsig</span>.<span class="ruby-constant">ByteRange</span>[<span class="ruby-value">3</span>]]
105:       
106:       <span class="ruby-identifier">signature</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKCS7</span>.<span class="ruby-identifier">sign</span>(<span class="ruby-identifier">certificate</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">signable_data</span>, <span class="ruby-identifier">ca</span>, <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKCS7</span><span class="ruby-operator">::</span><span class="ruby-constant">DETACHED</span> <span class="ruby-operator">|</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKCS7</span><span class="ruby-operator">::</span><span class="ruby-constant">BINARY</span>).<span class="ruby-identifier">to_der</span>
107:       <span class="ruby-identifier">digsig</span>.<span class="ruby-constant">Contents</span>[<span class="ruby-value">0</span>, <span class="ruby-identifier">signature</span>.<span class="ruby-identifier">size</span>] = <span class="ruby-identifier">signature</span>
108:       
109:       <span class="ruby-comment cmt">#</span>
110:       <span class="ruby-comment cmt"># No more modification are allowed after signing.</span>
111:       <span class="ruby-comment cmt">#</span>
112:       <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">freeze</span>
113:       
114:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000507" class="method-detail">
        <a name="M000507"></a>

        <div class="method-heading">
          <a href="#M000507" class="method-signature">
          <span class="method-name">to_bin</span><span class="method-args">(params = {})</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns the final binary representation of the current document.
</p>
<table>
<tr><td valign="top"><em><a href="PDF.html#M000508">rebuildxrefs</a></em>:</td><td>Computes xrefs while writing <a href="PDF.html#M000499">objects</a>
(default true).

</td></tr>
<tr><td valign="top"><em>obfuscate</em>:</td><td>Do some basic syntactic object obfuscation.

</td></tr>
</table>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000507-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000507-source">
<pre>
     <span class="ruby-comment cmt"># File origami/pdf.rb, line 512</span>
512:     <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_bin</span>(<span class="ruby-identifier">params</span> = {})
513:    
514:       <span class="ruby-identifier">has_objstm</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">indirect_objects</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">any?</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">obj</span><span class="ruby-operator">|</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">ObjectStream</span>)}
515: 
516:       <span class="ruby-identifier">options</span> =
517:       {
518:         <span class="ruby-identifier">:rebuildxrefs</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">true</span>,
519:         <span class="ruby-identifier">:obfuscate</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">false</span>,
520:         <span class="ruby-identifier">:use_xrefstm</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">has_objstm</span>,
521:         <span class="ruby-identifier">:use_xreftable</span> =<span class="ruby-operator">&gt;</span> (<span class="ruby-keyword kw">not</span> <span class="ruby-identifier">has_objstm</span>),
522:         <span class="ruby-identifier">:up_to_revision</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@revisions</span>.<span class="ruby-identifier">size</span>
523:         <span class="ruby-comment cmt">#todo linearize</span>
524:       }
525:       <span class="ruby-identifier">options</span>.<span class="ruby-identifier">update</span>(<span class="ruby-identifier">params</span>)
526: 
527:       <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:up_to_revision</span>] = <span class="ruby-ivar">@revisions</span>.<span class="ruby-identifier">size</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:up_to_revision</span>] <span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@revisions</span>.<span class="ruby-identifier">size</span>
528: 
529:       <span class="ruby-comment cmt"># Reset to default params if no xrefs are chosen (hybrid files not supported yet)</span>
530:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:use_xrefstm</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:use_xreftable</span>]
531:         <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:use_xrefstm</span>] = <span class="ruby-identifier">has_objstm</span>
532:         <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:use_xreftable</span>] = (<span class="ruby-keyword kw">not</span> <span class="ruby-identifier">has_objstm</span>)
533:       <span class="ruby-keyword kw">end</span>
534: 
535:       <span class="ruby-comment cmt"># Get trailer dictionary</span>
536:       <span class="ruby-identifier">trailer_info</span> = <span class="ruby-identifier">get_trailer_info</span>
537:       <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">trailer_info</span>.<span class="ruby-identifier">nil?</span>
538:         <span class="ruby-identifier">raise</span> <span class="ruby-constant">InvalidPDFError</span>, <span class="ruby-value str">&quot;No trailer information found&quot;</span>
539:       <span class="ruby-keyword kw">end</span>
540:       <span class="ruby-identifier">trailer_dict</span> = <span class="ruby-identifier">trailer_info</span>.<span class="ruby-identifier">dictionary</span>
541:  
542:       <span class="ruby-identifier">prev_xref_offset</span> = <span class="ruby-keyword kw">nil</span>
543:       <span class="ruby-identifier">xrefstm_offset</span> = <span class="ruby-keyword kw">nil</span>
544:       <span class="ruby-identifier">xreftable_offset</span> = <span class="ruby-keyword kw">nil</span>
545:     
546:       <span class="ruby-comment cmt"># Header</span>
547:       <span class="ruby-identifier">bin</span> = <span class="ruby-value str">&quot;&quot;</span>
548:       <span class="ruby-identifier">bin</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-ivar">@header</span>.<span class="ruby-identifier">to_s</span>
549:       
550:       <span class="ruby-comment cmt"># For each revision</span>
551:       <span class="ruby-ivar">@revisions</span>[<span class="ruby-value">0</span>, <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:up_to_revision</span>]].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">rev</span><span class="ruby-operator">|</span>
552:         
553:         <span class="ruby-comment cmt"># Create xref table/stream.</span>
554:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:rebuildxrefs</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span>
555:           <span class="ruby-identifier">lastno_table</span>, <span class="ruby-identifier">lastno_stm</span> = <span class="ruby-value">0</span>, <span class="ruby-value">0</span>
556:           <span class="ruby-identifier">brange_table</span>, <span class="ruby-identifier">brange_stm</span> = <span class="ruby-value">0</span>, <span class="ruby-value">0</span>
557:           
558:           <span class="ruby-identifier">xrefs_stm</span> = [ <span class="ruby-constant">XRef</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">0</span>, <span class="ruby-value">0</span>, <span class="ruby-constant">XRef</span><span class="ruby-operator">::</span><span class="ruby-constant">FREE</span>) ]
559:           <span class="ruby-identifier">xrefs_table</span> = [ <span class="ruby-constant">XRef</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">0</span>, <span class="ruby-constant">XRef</span><span class="ruby-operator">::</span><span class="ruby-constant">FIRSTFREE</span>, <span class="ruby-constant">XRef</span><span class="ruby-operator">::</span><span class="ruby-constant">FREE</span>) ]
560: 
561:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:use_xreftable</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span>
562:             <span class="ruby-identifier">xrefsection</span> = <span class="ruby-constant">XRef</span><span class="ruby-operator">::</span><span class="ruby-constant">Section</span>.<span class="ruby-identifier">new</span>
563:           <span class="ruby-keyword kw">end</span>
564: 
565:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:use_xrefstm</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span>
566:             <span class="ruby-identifier">xrefstm</span> = <span class="ruby-identifier">rev</span>.<span class="ruby-identifier">xrefstm</span> <span class="ruby-operator">||</span> <span class="ruby-constant">XRefStream</span>.<span class="ruby-identifier">new</span>
567:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">xrefstm</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">rev</span>.<span class="ruby-identifier">xrefstm</span>
568:               <span class="ruby-identifier">xrefstm</span>.<span class="ruby-identifier">clear</span>
569:             <span class="ruby-keyword kw">else</span>
570:               <span class="ruby-identifier">add_to_revision</span>(<span class="ruby-identifier">xrefstm</span>, <span class="ruby-identifier">rev</span>) 
571:             <span class="ruby-keyword kw">end</span>
572:           <span class="ruby-keyword kw">end</span>
573:         <span class="ruby-keyword kw">end</span>
574:        
575:         <span class="ruby-identifier">objset</span> = <span class="ruby-identifier">rev</span>.<span class="ruby-identifier">body</span>.<span class="ruby-identifier">values</span>
576:         
577:         <span class="ruby-identifier">objset</span>.<span class="ruby-identifier">find_all</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">obj</span><span class="ruby-operator">|</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">ObjectStream</span>)}.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">objstm</span><span class="ruby-operator">|</span>
578:           <span class="ruby-identifier">objset</span> <span class="ruby-operator">|=</span> <span class="ruby-identifier">objstm</span>.<span class="ruby-identifier">objects</span>
579:         <span class="ruby-keyword kw">end</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:rebuildxrefs</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:use_xrefstm</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span>
580: 
581:         <span class="ruby-comment cmt"># For each object, in number order</span>
582:         <span class="ruby-identifier">objset</span>.<span class="ruby-identifier">sort</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">obj</span><span class="ruby-operator">|</span>
583:          
584:           <span class="ruby-comment cmt"># Create xref entry.</span>
585:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:rebuildxrefs</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span>
586:            
587:             <span class="ruby-comment cmt"># Adding subsections if needed</span>
588:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:use_xreftable</span>] <span class="ruby-keyword kw">and</span> (<span class="ruby-identifier">obj</span>.<span class="ruby-identifier">no</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">lastno_table</span>).<span class="ruby-identifier">abs</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>
589:               <span class="ruby-identifier">xrefsection</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">XRef</span><span class="ruby-operator">::</span><span class="ruby-constant">Subsection</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">brange_table</span>, <span class="ruby-identifier">xrefs_table</span>)
590: 
591:               <span class="ruby-identifier">xrefs_table</span>.<span class="ruby-identifier">clear</span>
592:               <span class="ruby-identifier">brange_table</span> = <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">no</span>
593:             <span class="ruby-keyword kw">end</span>
594:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:use_xrefstm</span>] <span class="ruby-keyword kw">and</span> (<span class="ruby-identifier">obj</span>.<span class="ruby-identifier">no</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">lastno_stm</span>).<span class="ruby-identifier">abs</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>
595:               <span class="ruby-identifier">xrefs_stm</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">xref</span><span class="ruby-operator">|</span> <span class="ruby-identifier">xrefstm</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">xref</span> <span class="ruby-keyword kw">end</span>
596:               <span class="ruby-identifier">xrefstm</span>.<span class="ruby-constant">Index</span> <span class="ruby-operator">||=</span> []
597:               <span class="ruby-identifier">xrefstm</span>.<span class="ruby-constant">Index</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">brange_stm</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">xrefs_stm</span>.<span class="ruby-identifier">length</span>
598: 
599:               <span class="ruby-identifier">xrefs_stm</span>.<span class="ruby-identifier">clear</span>
600:               <span class="ruby-identifier">brange_stm</span> = <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">no</span>
601:             <span class="ruby-keyword kw">end</span>
602: 
603:             <span class="ruby-comment cmt"># Process embedded objects</span>
604:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:use_xrefstm</span>] <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">parent</span> <span class="ruby-operator">!=</span> <span class="ruby-identifier">obj</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">parent</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">ObjectStream</span>)
605:               <span class="ruby-identifier">index</span> = <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">parent</span>.<span class="ruby-identifier">index</span>(<span class="ruby-identifier">obj</span>.<span class="ruby-identifier">no</span>)
606:              
607:               <span class="ruby-identifier">xrefs_stm</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">XRefToCompressedObj</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">obj</span>.<span class="ruby-identifier">parent</span>.<span class="ruby-identifier">no</span>, <span class="ruby-identifier">index</span>)
608:               
609:               <span class="ruby-identifier">lastno_stm</span> = <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">no</span>
610:             <span class="ruby-keyword kw">else</span>
611:               <span class="ruby-identifier">xrefs_stm</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">XRef</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">bin</span>.<span class="ruby-identifier">size</span>, <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">generation</span>, <span class="ruby-constant">XRef</span><span class="ruby-operator">::</span><span class="ruby-constant">USED</span>)
612:               <span class="ruby-identifier">xrefs_table</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">XRef</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">bin</span>.<span class="ruby-identifier">size</span>, <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">generation</span>, <span class="ruby-constant">XRef</span><span class="ruby-operator">::</span><span class="ruby-constant">USED</span>)
613: 
614:               <span class="ruby-identifier">lastno_table</span> = <span class="ruby-identifier">lastno_stm</span> = <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">no</span>
615:             <span class="ruby-keyword kw">end</span>
616: 
617:           <span class="ruby-keyword kw">end</span>
618:          
619:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">parent</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">obj</span> <span class="ruby-keyword kw">or</span> <span class="ruby-keyword kw">not</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">parent</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">ObjectStream</span>)
620:            
621:             <span class="ruby-comment cmt"># Finalize XRefStm</span>
622:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:rebuildxrefs</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:use_xrefstm</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span> <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">obj</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">xrefstm</span>
623:               <span class="ruby-identifier">xrefstm_offset</span> = <span class="ruby-identifier">bin</span>.<span class="ruby-identifier">size</span>
624:    
625:               <span class="ruby-identifier">xrefs_stm</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">xref</span><span class="ruby-operator">|</span> <span class="ruby-identifier">xrefstm</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">xref</span> <span class="ruby-keyword kw">end</span>
626: 
627:               <span class="ruby-identifier">xrefstm</span>.<span class="ruby-constant">W</span> = [ <span class="ruby-value">1</span>, (<span class="ruby-identifier">xrefstm_offset</span>.<span class="ruby-identifier">to_s</span>(<span class="ruby-value">2</span>).<span class="ruby-identifier">size</span> <span class="ruby-operator">+</span> <span class="ruby-value">7</span>) <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">3</span>, <span class="ruby-value">2</span> ]
628:               <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">xrefstm</span>.<span class="ruby-constant">DecodeParms</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Dictionary</span>) <span class="ruby-keyword kw">and</span> <span class="ruby-identifier">xrefstm</span>.<span class="ruby-constant">DecodeParms</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">:Columns</span>)
629:                 <span class="ruby-identifier">xrefstm</span>.<span class="ruby-constant">DecodeParms</span>[<span class="ruby-identifier">:Columns</span>] = <span class="ruby-identifier">xrefstm</span>.<span class="ruby-constant">W</span>[<span class="ruby-value">0</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">xrefstm</span>.<span class="ruby-constant">W</span>[<span class="ruby-value">1</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">xrefstm</span>.<span class="ruby-constant">W</span>[<span class="ruby-value">2</span>]
630:               <span class="ruby-keyword kw">end</span>
631: 
632:               <span class="ruby-identifier">xrefstm</span>.<span class="ruby-constant">Index</span> <span class="ruby-operator">||=</span> []
633:               <span class="ruby-identifier">xrefstm</span>.<span class="ruby-constant">Index</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">brange_stm</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">xrefs_stm</span>.<span class="ruby-identifier">size</span>
634:    
635:               <span class="ruby-identifier">xrefstm</span>.<span class="ruby-identifier">dictionary</span> = <span class="ruby-identifier">xrefstm</span>.<span class="ruby-identifier">dictionary</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">trailer_dict</span>) 
636:               <span class="ruby-identifier">xrefstm</span>.<span class="ruby-constant">Prev</span> = <span class="ruby-identifier">prev_xref_offset</span>
637:               <span class="ruby-identifier">rev</span>.<span class="ruby-identifier">trailer</span>.<span class="ruby-identifier">dictionary</span> = <span class="ruby-keyword kw">nil</span>
638: 
639:               <span class="ruby-identifier">add_to_revision</span>(<span class="ruby-identifier">xrefstm</span>, <span class="ruby-identifier">rev</span>)
640: 
641:               <span class="ruby-identifier">xrefstm</span>.<span class="ruby-identifier">pre_build</span>
642:               <span class="ruby-identifier">xrefstm</span>.<span class="ruby-identifier">post_build</span>
643:             <span class="ruby-keyword kw">end</span>
644: 
645:             <span class="ruby-identifier">bin</span> <span class="ruby-operator">&lt;&lt;</span> (<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:obfuscate</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">to_obfuscated_str</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">to_s</span>)
646:           <span class="ruby-keyword kw">end</span>
647:         }
648:       
649:         <span class="ruby-identifier">rev</span>.<span class="ruby-identifier">trailer</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">Trailer</span>.<span class="ruby-identifier">new</span>
650:         
651:         <span class="ruby-comment cmt"># XRef table</span>
652:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:rebuildxrefs</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span>
653:  
654:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:use_xreftable</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span>
655:             <span class="ruby-identifier">table_offset</span> = <span class="ruby-identifier">bin</span>.<span class="ruby-identifier">size</span>
656:             
657:             <span class="ruby-identifier">xrefsection</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">XRef</span><span class="ruby-operator">::</span><span class="ruby-constant">Subsection</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">brange_table</span>, <span class="ruby-identifier">xrefs_table</span>)
658:             <span class="ruby-identifier">rev</span>.<span class="ruby-identifier">xreftable</span> = <span class="ruby-identifier">xrefsection</span>
659:  
660:             <span class="ruby-identifier">rev</span>.<span class="ruby-identifier">trailer</span>.<span class="ruby-identifier">dictionary</span> = <span class="ruby-identifier">trailer_dict</span>
661:             <span class="ruby-identifier">rev</span>.<span class="ruby-identifier">trailer</span>.<span class="ruby-constant">Size</span> = <span class="ruby-identifier">objset</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
662:             <span class="ruby-identifier">rev</span>.<span class="ruby-identifier">trailer</span>.<span class="ruby-constant">Prev</span> = <span class="ruby-identifier">prev_xref_offset</span>
663: 
664:             <span class="ruby-identifier">rev</span>.<span class="ruby-identifier">trailer</span>.<span class="ruby-constant">XRefStm</span> = <span class="ruby-identifier">xrefstm_offset</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:use_xrefstm</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span>
665:           <span class="ruby-keyword kw">end</span>
666: 
667:           <span class="ruby-identifier">startxref</span> = <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:use_xreftable</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">table_offset</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">xrefstm_offset</span>
668:           <span class="ruby-identifier">rev</span>.<span class="ruby-identifier">trailer</span>.<span class="ruby-identifier">startxref</span> = <span class="ruby-identifier">prev_xref_offset</span> = <span class="ruby-identifier">startxref</span>
669: 
670:         <span class="ruby-keyword kw">end</span> <span class="ruby-comment cmt"># end each rev</span>
671:         
672:         <span class="ruby-comment cmt"># Trailer</span>
673: 
674:         <span class="ruby-identifier">bin</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">rev</span>.<span class="ruby-identifier">xreftable</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-identifier">:use_xreftable</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span>
675:         <span class="ruby-identifier">bin</span> <span class="ruby-operator">&lt;&lt;</span> (<span class="ruby-identifier">options</span>[<span class="ruby-identifier">:obfuscate</span>] <span class="ruby-operator">==</span> <span class="ruby-keyword kw">true</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">rev</span>.<span class="ruby-identifier">trailer</span>.<span class="ruby-identifier">to_obfuscated_str</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">rev</span>.<span class="ruby-identifier">trailer</span>.<span class="ruby-identifier">to_s</span>)
676:         
677:       <span class="ruby-keyword kw">end</span>
678:       
679:       <span class="ruby-identifier">bin</span>
680:     <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>